Skip to content

Problem with passing a not iterable argument in Promise.all() #128

@anvk

Description

@anvk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions