11

bluebird ライブラリはPromise::then、promise で "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)
});

これは es6 Promise API の契約ですか? たとえば、ここまたはここでこの平坦化動作について言及されていません。

4

1 に答える 1