Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anvk opened this issue Jul 8, 2016 · 0 comments
Open

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

anvk opened this issue Jul 8, 2016 · 0 comments

Comments

@anvk
Copy link

anvk commented Jul 8, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant