javascript 中的扁平化承诺
Flattening promises in javascript
bluebird 库似乎自动使用 Promise::then
作为 "map" 和 "flatMap" 的等价物,例如,请参阅此示例。
var Promise;
Promise = require('bluebird').Promise;
Promise.resolve(1).then(function(x) {
return Promise.resolve(x + 1);
}).then(function(x) {
return console.log(x); // => `2` (not a promise)
});
Promise.resolve(1).then(function(x) {
return x + 1;
}).then(function(x) {
return console.log(x); // => `2`
});
Promise.reject('hi').catch(function(x) {
return Promise.reject('hi2');
}).catch(function(x) {
return console.error(x); // => `hi2` (not a promise)
});
Is this a contract of the es6 Promise API?
是的,是Promises/A+, and has made its way from there into the ES6 specification. You will find some discussions here, here and here建立的契约。
bluebird 库似乎自动使用 Promise::then
作为 "map" 和 "flatMap" 的等价物,例如,请参阅此示例。
var Promise;
Promise = require('bluebird').Promise;
Promise.resolve(1).then(function(x) {
return Promise.resolve(x + 1);
}).then(function(x) {
return console.log(x); // => `2` (not a promise)
});
Promise.resolve(1).then(function(x) {
return x + 1;
}).then(function(x) {
return console.log(x); // => `2`
});
Promise.reject('hi').catch(function(x) {
return Promise.reject('hi2');
}).catch(function(x) {
return console.error(x); // => `hi2` (not a promise)
});
Is this a contract of the es6 Promise API?
是的,是Promises/A+, and has made its way from there into the ES6 specification. You will find some discussions here, here and here建立的契约。