Here is how I would write it with streamline (if I understand it well):
var flows = require('streamline/lib/util/flows');
function timeyWimeyBall(endpoint, obody, _) {
var resp1 = localPost(endpoint, obody, [_]);
var fut = localGet(resp1[0].headers.location, !_); // don't wait, get a
future
return function answerer(expected, _) {
var resp2 = localGet(endpoint, [_]);
localPost(resp2[0].headers.location, expected, !_); // don't wait on
this one either
// resolve the GET future now
var answer = fut([_]);
assert(answer[1] === expected);
}
}
try {
// start the two operations in parallel (as futures) and collect the
answerers
var answerers = flows.collect([
timeyWimeyBall('/offers/point-a', 'Offer A initial body', !_),
timeyWimeyBall('/offers/point-b', 'Offer B initial body', !_)], _);
// start the answerers in parallel and wait for their results
flows.collect([
answerers[0]('Answer A initial body', !_),
answerers[1]('Answer B initial body', !_)], _);
// DONE will be printed after everything has been evaluated
console.log("DONE");
} catch (ex) {
// if anything goes wrong, well end up here
console.log("ERROR: " + ex.stack);
}
I find it a bit strange to have the POST use the location returned by a GET
in the second part (the answerer). I would have expected the reverse but
this is how the example was setup.
Bruno
--
--
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.