蓝鸟图书馆似乎是自动使用的 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)
});