var drop = false;
doRequestA(handleRequest);
doRequestB(handleRequest);
doRequestC(handleRequest);
function handleRequest(err, response) {
  if (err) {
    return;
  }
  if (drop) {
    return;
  }
  drop = true;
  doSomethingWithResponse(response);
}

OR

var requests = [];

requests.push(doRequestA(handleResponse));
requests.push(doRequestB(handleResponse))
requests.push(doRequestC(handleResponse))

function handleResponse(err, response) {
  var r;
  while(r = requests.shift()) {
    terminateRequest(r);
  }
  doSomethingWithResponse(response);
}


in each case, doSomethingWithResponse ends the express response with the 
results.
On Monday, 1 July 2013 21:47:54 UTC+2, Nate D wrote:
>
> Sorry for long title, been hunting around trying to find a usable 
> example/pattern to solve this pattern, no luck yet.
>  
> I am building a service to take REST calls to an express fronted service.  
> A search is being performed, and for each search request coming into 
> express I need to perform 3-5 parallel requests to various 
> databases/indexes/etc.
>  
> The behavior is such that we want to get a response back ASAP to the user, 
> and want to search across all sources in parallel, but early terminate as 
> soon as the first one returns a found result and push the result to the end 
> user.
>  
> Have used async module for some tasks, but not sure its a workable thing 
> to bolt into express routes.  Hoping to not have to hack into an existing 
> module
>  
> Any patterns or modules people have used to accomplish this "parallel with 
> early termination/response" method?
>  
>  
> NOTE: not married to express, just need simple setup to take http/REST 
> call and route to a function which will spin off the parallel calls and 
> handle the response
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to