JavaScript Promise.all not working when it's returned from a .then() callback

I'm using Promise Node.js library and I'd like to do the following:

  1. Execute async operation that returns a Promise.
  2. When that operation completes, return a Promise that is completed when two paralell async operations complete.

The code I'm using is the following:

var Promise = require('promise');

var resolved1 = Promise.resolve(1);

var resolvedAll = resolved1.then(function() {
  return Promise.all(Promise.resolve(2), Promise.resolve(3));
});

var print = resolvedAll.then(function(values) {
  console.log(values);
});

print.done(function () {
  console.log('done');
});

But this code is not working as expected, since it prints:

[]
done

From docu, Promise.all returns a promise that resolves when all of the promises in the iterable argument have resolved. So in theory resolvedAll should not complete until all the promises passed to Promise.all have completed, but that's not what is happening here.

Any idea why Promise.all not working as expected? Could this be a bug? Anyone aware of alternatives to return multiple promises out of a .then() callback?

Cheers, Galder

Answer:1

I have a big problem with this plugin: https://github.com/katzer/cordova-plugin-email-composer when i tried to send email on ios, all work well. but when i tried in Android, it did nothing.. And i ...

I have a big problem with this plugin: https://github.com/katzer/cordova-plugin-email-composer when i tried to send email on ios, all work well. but when i tried in Android, it did nothing.. And i ...

  1. cordova email composer plugin
  2. cordova email composer
  3. cordova email composer not working in android
  4. cordova email composer not working
  5. phonegap email composer example
  6. cordova-plugin-email-composer ionic
  7. cordova-plugin-email-composer not working
  8. cordova-plugin-email-composer example
  9. ionic cordova email composer
  10. cordova plugin email composer github
  11. cordova-plugin-email-composer versions
  12. cordova-plugin-email-composer npm
  13. cordova-plugin-email-composer attachment
  14. cordova-plugin-email-composer callback
  15. cordova-plugin-email-composer ionic 3
  16. cordova-plugin-email-composer permissions
  17. cordova-plugin-email-composer android example
  18. cordova-plugin-email-composer undefined
  19. cordova-plugin-email-composer 0.8.2
  20. cordova-plugin-email-composer angular

I'm making a large Meteor app and all my templates are now named "veryLongNameOfMyTemplate". I want to avoid having such long names. I tried to create my templates in packages but I have a strange ...

I'm making a large Meteor app and all my templates are now named "veryLongNameOfMyTemplate". I want to avoid having such long names. I tried to create my templates in packages but I have a strange ...

  1. create scoped package npm
  2. create scoped package
  3. command to create scoped package

This question will need to be answered in Javascript. For example, I have an array of phone numbers: var phoneNumbers = ['123-434-4455', '123-495-8475', '484-728-3456']; The phone number at index 0 ...

This question will need to be answered in Javascript. For example, I have an array of phone numbers: var phoneNumbers = ['123-434-4455', '123-495-8475', '484-728-3456']; The phone number at index 0 ...

I have a node.js + Express + express-handlebars app. I want to redirect the users to 404 page when they go to a page that does not exists and redirect them to a 500 when there is an internal server ...

I have a node.js + Express + express-handlebars app. I want to redirect the users to 404 page when they go to a page that does not exists and redirect them to a 500 when there is an internal server ...

  1. handling exceptions node.js
  2. handle all exceptions node
  3. handling uncaught exceptions in node js