fate

Futures, Promises and Deferreds. Closure-based implumentation of Promises/A+ spec.

Fate is a closure based implementation of Promises/A+

A promise is an object with a then(onFulfilled, onRejected) closure, making a promise a thenable object.

A future is a thenable with bound fulfill(value) and reject(reason) closures. In fate, a future is also a valid node style function(err,arg) callback.

fate.deferred() returns an unresolved (pending) future.

fate.fulfilled(value) returns a fulfilled promise.

fate.rejected(reason) returns a rejected promise.

inverted(aFuture) returns a promise that transposes onFulfilled and onRejected.

delay(ms, bFulfill=false) returns a deferred() that will be answered after ms timeout.

timeout(target, ms) returns a delay(ms) that will additionally be answered upon target being answered.

each(anArray) is a compound deferred() answered after all promises in anArray are either rejected or fulfilled.

Fulfilled if all promise are fulfilled from anArray.

Rejected if any promises is rejected from anArray.

all(anArray) is a compound deferred() answered after all promises are fulfilled, or when any promise is rejected.

Fulfilled if any promise is fulfilled from anArray.

Rejected if all promises are rejected from anArray.

first(anArray) is a compound deferred() answered after any promise is either fulfilled or rejected.

Fulfilled if any promise is fulfilled from anArray.

Rejected if all promises are rejected from anArray.

any(anArray) is a compound deferred() answered after any promise is fulfilled, or when all are rejected.

Fulfilled if any promise is fulfilled from anArray.

Rejected if all promises are rejected from anArray.