Appendix A: asynquence Library
Chapters 1 and 2 went into quite a bit of detail about typical asynchronous programming patterns and how they’re commonly solved with callbacks. But we also saw why callbacks are fatally limited in capability, which led us to Chapters 3 and 4, with Promises and generators offering a much more solid, trustable, and reason-able base to build your asynchrony on.
I referenced my own asynchronous library asynquence (http://github.com/getify/asynquence) — “async” + “sequence” = “asynquence” — several times in this book, and I want to now briefly explain how it works and why its unique design is important and helpful.
In the next appendix, we’ll explore some advanced async patterns, but you’ll probably want a library to make those palatable enough to be useful. We’ll use asynquence to express those patterns, so you’ll want to spend a little time here getting to know the library first.
asynquence is obviously not the only option for good async coding; certainly there are many great libraries in this space. But asynquence provides a unique perspective by combining the best of all these patterns into a single library, and moreover is built on a single basic abstraction: the (async) sequence.
My premise is that sophisticated JS programs often need bits and pieces of various different asynchronous patterns woven together, and this is usually left entirely up to each developer to figure out. Instead of having to bring in two or more different async libraries that focus on different aspects of asynchrony, asynquence unifies them into variated sequence steps, with just one core library to learn and deploy.
I believe the value is strong enough with asynquence to make async flow control programming with Promise-style semantics super easy to accomplish, so that’s why we’ll exclusively focus on that library here.
To begin, I’ll explain the design principles behind asynquence, and then we’ll illustrate how its API works with code examples.