Promise.resolve(value)
value
value
is a promise, just returns value
Promise.reject(value)
value
promise.catch
fn
Assume callback passed to fn
takes two arguments: callback(error, data)
, where error
is null
if successful, and data
is null if unsuccessful.
new Promise(function(resolve, reject) {
fn(function(error, data) {
if (error) {
reject(error);
}
else {
resolve(data);
}
});
});
promise
.then(function() { ... })
.catch(function(err) {
console.log(err.stack);
});
new Promise(fn)
fn
takes two arguments: resolve
and reject
resolve
and reject
are both functions which can be called with one argumentpromise.then(onResolve, onReject)
onResolve
or onReject
onReject
promise.catch
promise.catch(onReject)
promise.then(null, onReject)
Promise.all([promise1, promise2, ...])