callback is passed an object keyed by names and valued by numbers between 0.0 and 1.0. If promise has already been kept or failed, callback is ignored and discarded. callback may be called any number of times, or never called at all. callback is only called while promise is unresolved. If defined and not null, context will be this in callback.Ĭalls callback whenever there is progress to report. If promise has already been kept or failed, callback runs immediately. If defined and not null, context will be this in callback.Ĭalls callback when promise either keeps or fails. callback is passed the error object representing the reason for the failure, which was passed to fail() method triggering the failure. If promise already failed, callback runs immediately. If defined and not null, context will be this in callback.Ĭalls callback when promise fails. callback is passed a map of all the things in the promise, keyed by the strings passed to await(). If the promise is already fulfilled, callback runs immediately. Exceptions thrown by callback automatically fail the promise.Ĭalls callback when every item of the promise is fulfilled. If defined and not null, context will be this in callback. callback is passed a reference to the promise. Runs callback immediately (synchronously), which contains whatever promise fulfillment logic you want. Accepts one or more args which can be strings or other promises, which allows grouping. Returns a promise, pending the fulfillment of the given set of things. 'foo' is kept with value b, a is ignored API overview method If the mapping you provide conflicts with direct matches, the mapping wins: You can therefore optionally provide a mapping object: p1.take(p2, ) In other words, p1 only took the intersection of itself with p2. P1 now takes p2, and if p2 fails, p1 fails.Īs you can see, p2 is a different set of things than p1. Here we've declared two promises, and we want to take the outcome of one and plug it into the other: p1 = await('foo', 'bar', 'baz') Promises can be explicitly chained instead of grouped. However for convenience, it does inherit several array-like accessor methods from its prototype: Note that in the above example, gots is an object, not a true array, despite having length, 0, 1 (etc) properties.įor example it doesn't have mutator methods like push() or splice(). You create a promise by calling the await() function and passing a series of strings one for each slot you expect to be filled. Once in either a kept or failed state, a promise will never switch to any other state. The promise can't enter the failed state if it has already entered the kept state, or vice versa. If something goes wrong during fulfillment, the promise enters the failed state. It doesn't matter how long it takes or in what order they're filled, or whether it's done serially or in parallel. Sometimes it's useful to think in terms of it being unresolved or resolved, where resolved means either kept or failed.Ī promise starts out in an unresolved state.Īs soon as each individual slot has been filled, the promise enters the kept state. How does it work?Īn await promise represents a set of empty slots that need to be filled.Ī promise can be in one of three states: unresolved, kept or failed. The polyfills file has no test coverage, and is otherwise purely optional. To that end, example-polyfills.js is included in the git repo. You'll need some polyfill or Modernizr goodness to use it in browsers that don't support JavaScript 1.8.5.
0 Comments
Leave a Reply. |