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

feature request - async.minimum #899

Closed
ORESoftware opened this issue Sep 1, 2015 · 6 comments
Closed

feature request - async.minimum #899

ORESoftware opened this issue Sep 1, 2015 · 6 comments

Comments

@ORESoftware
Copy link
Contributor

I am looking for the functionality described here:

http://stackoverflow.com/questions/32323611/node-js-async-but-with-minimum-priority

the question is:
What is the best way to create parallel asynchronous HTTP requests and take the first result that comes back positive?

//something like this, where one call goes to some API and a parallel call goes to our Redis store to see if we already have the value:

async.minimum([

function apiRequest(cb){
   request(opts,function(err,response,body){
         cb(err,body.result.hit);
    }
},
function redisRequest(cb){
   client.get("some_key", function(err, reply) {
          cb(err,reply.result.hit);
     });
}], 

  function minimumCompleted(err,result){

   // this mimimumCompleted final callback function will be only fired once, 
   // and would be fired by one of the above functions - 
   // whichever one had a value for body.result.hit that was defined


 });
@megawac
Copy link
Collaborator

megawac commented Sep 1, 2015

Take a look at async.find asyc.detect, which I believe is what you want

@aearly
Copy link
Collaborator

aearly commented Sep 1, 2015

I think they mean something more like async.first from #568 . But async.detect should work until we sort that one out.

@aearly
Copy link
Collaborator

aearly commented Sep 1, 2015

Closing this in favor of #568 . I'll add minimum to the list of potential names. :P

@aearly aearly closed this as completed Sep 1, 2015
@ORESoftware
Copy link
Contributor Author

I think "first" is actually better than "minimum". The only problem with "first", is that the result I want is not just the first result, it is the first result that has a defined value for the second callback parameter, the first being a potential error, as in error first callback.

This is something that could be easily generified for popular use.

@aearly
Copy link
Collaborator

aearly commented Sep 1, 2015

Yeah, "first" is not without its problems. I think coming up with a good name is most of the work remaining for that feature. "Cache invalidation and naming things" as the saying goes.

@ORESoftware
Copy link
Contributor Author

http://www.thesaurus.com/browse/pristine async.pristine haha, pristine seems to mean both earliest and immaculate

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

3 participants