Asynchronicity is great, but javascript doesn't provide the tools to do it properly.
> (...) try writing a function call that requires information from two separate HTTP API responses; I basically need to draw a diagram of what happens with async.waterfall for a task that, given synchronicity, would've been solved with a trivial three-liner.
It's a lot easier to handle asynchronicity in strongly-typed languages with monadic for comprehensions. In Scala, for example:
val res: Future[Foobar] = for {
a <- makeHttpRequestA()
b <- makeHttpRequestBFromA(a)
} yield new Foobar(a, b)
You can then register callback functions which operate on either a Success[Foobar] or a Failure[Throwable].
Synchronous code isn't simpler, it just hides complexity like caltrops in tall grass.
co(function *(){
let promiseA = makeHttpRequestA()
let promiseB = makeHttpRequestBFromA(yield promiseA)
var res = new Foobar(yield promiseA, yield promiseB);
})();
> (...) try writing a function call that requires information from two separate HTTP API responses; I basically need to draw a diagram of what happens with async.waterfall for a task that, given synchronicity, would've been solved with a trivial three-liner.
It's a lot easier to handle asynchronicity in strongly-typed languages with monadic for comprehensions. In Scala, for example:
You can then register callback functions which operate on either a Success[Foobar] or a Failure[Throwable].Synchronous code isn't simpler, it just hides complexity like caltrops in tall grass.
(slightly modified version of my post on Github)