Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants