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

asynchronous for each #780

Closed
darkdragon-001 opened this issue May 3, 2016 · 1 comment
Closed

asynchronous for each #780

darkdragon-001 opened this issue May 3, 2016 · 1 comment

Comments

@darkdragon-001
Copy link

I find myself doing the following over and over again:

var items = [1,2,3,4]; // some array
var itemsP = items.map(function(item){
  // do some blocking operation with item which returns a promise
  return item;
});
return q.all(itemsP);

Maybe it makes sense do define a function Q.each or Q.map as follows

Q.each = function(arr, func) {
  return q.all(arr.map(func));
}
@benjamingr
Copy link
Collaborator

I think the API surface is pretty frozen at this point, but you can either use a library with these helpers like https://github.com/petkaantonov/bluebird or implement them yourself (like you did above)

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

2 participants