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

applyEach should surface results from the input functions #1501

Closed
hhowe29 opened this issue Nov 30, 2017 · 1 comment
Closed

applyEach should surface results from the input functions #1501

hhowe29 opened this issue Nov 30, 2017 · 1 comment

Comments

@hhowe29
Copy link

hhowe29 commented Nov 30, 2017

I could utilize applyEach more often if it provided a way to collect results from each input function. Please allow me to write code link this:

async.applyEach([func0, func1, ... funcN], 'foo', 29, (error, results) => {
   if(error) {
     console.log('guess you are out of luck');
   }   
  else {
    // results == array of N+1 result values
    console.log('func0(foo, 29) returned ' + results[0]);
    console.log('func1(foo, 29) returned ' + results[1]);
    ...
  }
});

This is similar map, but inverted from SIMD to MISD.

@hargasinski
Copy link
Collaborator

Hi @hhowe29,

Thanks for the question! applyEach behaves the same way as map in this regard (it's actually implemented using map internally) so you can already do that. The documentation for it is just missing right now.

const func0 = (foo, bar, cb) => { cb(null, 'foo'); };
const func1 = (foo, bar, cb) => { cb(null, 'bar'); };

async.applyEach([func0, func1], 'foo', 29, (err, results) => {
  if (err) {
    // handle err
  }
  // results is ['foo', 'bar']
});

If you have an idea for including this in the docs, a PR would be awesome!

@aearly aearly closed this as completed in d1374d0 Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants