Skip to content

Instantly share code, notes, and snippets.

@SomeKittens
Created May 18, 2014 06:38
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 SomeKittens/15658ef0ac9e82cfdfea to your computer and use it in GitHub Desktop.
Save SomeKittens/15658ef0ac9e82cfdfea to your computer and use it in GitHub Desktop.
for loop bluebird promise
var userPromises = [];
// For loop instead of forEach to maintain `this` value
for (var i = 0; i < users.length; i++) {
userPromises.push(this.client.queryAsync('INSERT INTO invites (customerNo, email, name)' +
' VALUES ($1, $2, $3)', [req.user.id, users[i].email, users[i].name]));
}
return bluebird.all(userPromises);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment