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

async.each should include a results array to the callback #1139

Closed
pcman312 opened this issue May 2, 2016 · 8 comments
Closed

async.each should include a results array to the callback #1139

pcman312 opened this issue May 2, 2016 · 8 comments

Comments

@pcman312
Copy link

pcman312 commented May 2, 2016

It would be extremely useful to have the each() call include a results array to its callback.

@aearly
Copy link
Collaborator

aearly commented May 2, 2016

That's what async.map is for.

@aearly aearly closed this as completed May 2, 2016
@jhagege
Copy link

jhagege commented Jul 12, 2016

Hi,
Indeed map works exactly like you described @aearly.
Although in terms of code readibility I agree with @pcman312 it would be nice to have eachSeries have a callback (err, results).

This would make it consistent with async.series which also has a callback(err, results).

i.e: One may want to run a function for each element in a collection but the goal of this function would not be to "map" values. (in this case, eachSeries or each would be better readability).

Any chance you could still consider implementing it the same as async.series regarding the results returned ? Thanks a lot !

@megawac
Copy link
Collaborator

megawac commented Jul 12, 2016

I don't think this is worth considering as this functionality is already 100% covered by mapSeries. If you care about the results of your functions than you are mapping

series and mapSeries are also quite different as series is providing you the result of your last callback whereas mapSeries is mapping the result of each callback in an array

@ex1st
Copy link

ex1st commented Jul 12, 2016

@megawac

are also quite different as series is providing you the result of your last callback

No, series also mapping the result of each callback.

@megawac
Copy link
Collaborator

megawac commented Jul 12, 2016

Whoops my bad, was mixing it up with waterfall. Anyway, my comment still stands in regards to mapSeries

@jhagege
Copy link

jhagege commented Jul 12, 2016

Sounds good guys, no problem, probably needs to get used to the syntax :-)
Thanks for your time and for the great library in any case !

@aearly
Copy link
Collaborator

aearly commented Jul 13, 2016

each is also slightly faster since it doesn't have to keep track of the results.

@knoxcard
Copy link

knoxcard commented May 29, 2018

I came across this today, which I think is absolutely brilliant...in case you are needing the ID.
If there is something more simple than this, please let me know.

async.each(Object.keys(arr), function(index, cb) {
  console.log('index: ' + index)
  var item = arr[index]
  console.log(item)
  cb()
}, (err, ret) {
  console.log('done')
})

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

6 participants