-
-
Notifications
You must be signed in to change notification settings - Fork 316
Open
Description
We just spent a day yesterday to debug a very weird "bug" in NPM Promise library. We forgot to put array brackets for Promise.all()
function but the code still worked... The worst part that it was very hard to debug since our async functions looked fine and worked fine, but the final Promise.all()
was doing bizarre things.
Take a look at this fiddle
Now go to online npm prototyping environment and paste the following code (which is almost identical to the one in the fiddle)
var Promise = require('promise');
function async(options) {
options = options || {};
return new Promise(function(resolve, reject) {
setTimeout(function() {
console.log('async func complete. going to resolve', options.value);
resolve(options.value);
}, options.time);
});
}
// no array was passed into the Promise.all()
Promise.all(
async({
value: 'Hello',
time: 2000
}),
async({
value: 'Alex',
time: 1000
})
)
.then(function(result) { console.log('All done. Our result is:'); console.log(result); })
.catch(function(error) { console.log(error); });
Browser version of promise works properly and throws and error TypeError: Argument of Promise.all is not iterable
. NPM module works and its result is very confusing.
AlexSicoe, ItsTarik, mandaputtra, nsa-itv, anovak89 and 2 more
Metadata
Metadata
Assignees
Labels
No labels