Many developers new to Node.js struggle with writing asynchronous code in a clean, concise, easy to maintain manner. There are many strategies for managing and preventing 'callback hell' in Node.js. We'll walk through many of those strategies, from Promises to Generators to flow control libraries, and show that with a bit of forethought, writing asynchronous code in Javascript and Node.js can be easy and maintainable.
50. There’s nothing forcing
you to write ten levels of
nested callbacks, but
the pattern does make
it easy for you to do so.
- Raymond Julin (paraphrased)
108. function run(generator) {
function resume(ret) {
var obj = itr.next(ret)
if (obj.done) return
obj.value(resume)
}
var itr = generator()
resume()
}
109. function* delayThings() {
var results1 = yield delay(1000)
console.log(results1)
!
var results2 = yield delay(1200)
console.log(results2)
}
!
run(delayThings)