Geo*_*mms 11 javascript promise ecmascript-6 es6-promise
蓝鸟图书馆似乎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)
});
Run Code Online (Sandbox Code Playgroud)