Created
February 17, 2016 19:44
-
-
Save iaean/8bb010727c6ec576e38e to your computer and use it in GitHub Desktop.
bluebird .mapSeries() node issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict'; | |
var Promise = require('bluebird'); | |
console.error(Promise.prototype.mapSeries); | |
function delayResolve(t) { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { resolve(t); }, t); }); } | |
function delayReject(t) { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { reject(t); }, t); }); } | |
// .mapSeries() throws error... | |
// [email protected] and [email protected] | |
var p0 = Promise.resolve(delayResolve(200)); // or p0 = delayResolve(200); | |
p0.then(function() { | |
var p1 = delayResolve(500); | |
var p2 = delayReject(300); | |
var p3 = delayResolve(400); | |
// resolved on settleAll (http://bluebirdjs.com/docs/api/reflect.html) | |
return Promise.all([p1,p2,p3].map(function(p) { | |
return p.reflect(); })); | |
}) | |
.mapSeries(function(p) { | |
return p.isFulfilled() ? p.value() : null; | |
}) | |
.then(function(r) { | |
console.log(JSON.stringify(r)); | |
}); | |
/* | |
/.../b3.js:30 | |
.mapSeries(function(p) { | |
^ | |
TypeError: p0.then(...).mapSeries is not a function | |
at Object.<anonymous> (/.../b3.js:30:2) | |
at Module._compile (module.js:410:26) | |
at Object.Module._extensions..js (module.js:417:10) | |
at Module.load (module.js:344:32) | |
at Function.Module._load (module.js:301:12) | |
at Function.Module.runMain (module.js:442:10) | |
at startup (node.js:136:18) | |
at node.js:966:3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment