Adding Asynquence
Video Course on Real-Time HTML5 with Node.jsredo the previous exercise Simulating Asyncronicity with the asynquence library
my solution (inside
handleHTTP(req, res)
):
function createTest(done) {
var message = "Hello World " + Math.random();
done(message)
}
function sendresponse(done, contents){
res.writeHead(200,{
"Content-type": "text/html"
});
res.end(contents);
}
ASQ()
.then(createTest)
.then(sendresponse);
his solution:
ASQ(function(done){
setTimeout(function(){
done(Math.random());
},1000);
})
.then(function(done,num){
setTimeout(function(){
done("Hello world: " +num);
}, 1000);
})
.val(function(msg){
res.end(msg)
});
in my solution I could have used .val
like so:ASQ().then(createTest).val(sendresponse);
and sendresponse
would only take a contents parameter (no done):function sendresponse(contents){//...}