Node.js: Asynchronous I/O for Fun and Profit
Recorded at:
Handling Asynchronous Computations
by
Faisal Waris
Consider for example the F# async monad. To sequence three async calls with data dependencies between them is as simple as writing the following:
async {
let! data1 = asyncCall1()
let! data2 = asyncCall2(data1)
let! data3 = asyncCall2(data2)
return data3
} |> Async.Start
Notice that no nesting of callbacks is required.
And this is all statically type checked. Type inference means very little explicit type information is needed.
Try-catch, sleep, timers, events, async io, etc., all work in async monads without thread blocking.
Similarly fork-join of 3 independent calls is as simple as:
[
asyncCall1();
asyncCall2();
asyncCall3()
] |> Async.Parallel |> Async.Start
You can compose async monads together for handling many complex scenarios.
In moving off of java, the smart people at Node.js maybe should have cast the net a bit wider than just javascript.
Anyone interested understanding the essence of monads can check out this post: fwaris.wordpress.com/2011/07/30/understanding-m...
Re: Handling Asynchronous Computations
by
Axel Rauschmayer




Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think