polyfill standard Promises to old versions of node
Use this to ensure the Promise constructor is available, even in old versions of node (< 0.12) or browsers
var Promise = require'polyfill-promise'// either native or polyfilledvar foo = Promiseresolve'foo'foothen
require'polyfill-promise/register'// global Promise constructor is now availablevar foo = Promiseresolve'foo'foothen
If polyfill is used, this read-only property is set to true. If a native implementation is available, this property is undefined.
additionally, implements the Promise api. Quick reference:
Creates a pending promise. Pass it a
factory function which wraps the asynchronous operation.
factory is called with two functions,
resolve which should be called when the asynchronous operation is complete or an exception ocurrs.
Example: delay a value by an amount of time
Example: wrap a node-style callback
var result =asyncFnif err rejecterr; returnresolveresult
Create a Promise which is immediately rejected with an optional
Create a Promise which is immediately resolved with an optional
Returns a Promise which is resolved when all of the Promises in the
promises array are resolved, or rejected if any of them is rejected. The resolved value is an Array of the resolved values in the same order.
Returns a Promise which is resolved as soon as the first Promise in the
promises array is resolved, or rejected when the first Promise in the
promises array is rejected. Since a Promise can only be either resolved or rejected but not both, if one Promise in
promises is resolved and then another one is rejected, the resulting Promise will still be resolved and will ignore the later rejection.
Chains a function
fn on the Promise to be evaluated when the Promise is resolved. The return value of
fn is resolved to a new Promise which allows for chaining and composition.
An optional second parameter is an error handling function which is called if the Promise is rejected.
Chains an error handling function to a Promise chain which will be called if a Promise is rejected. Returns a new Promise.
$ npm test
by jden email@example.com, ISC license