Skip to content

Instantly share code, notes, and snippets.

@chinmay185
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chinmay185/ef51e4a0ea820e3c1f98 to your computer and use it in GitHub Desktop.
Save chinmay185/ef51e4a0ea820e3c1f98 to your computer and use it in GitHub Desktop.
using q.all and q.spread to straighten promises
var q = require("q");
// v1
q.all([getUser(username1), getUser(username2)])
.then(function(users) {
makeFriends(users[0], users[1]);
});
// v2 (even better)
q.all([fetchUser(username1), fetchUser(username2)])
.spread(function(user1, user2) {
makeFriends(user1, user2);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment