Chapter 5. Control Flow, Asynchronous Patterns, and Exception Handling
Node might seem intimidating at times, with discussions about
asynchronous events and callbacks and new objects such as EventEmitter
ânot to mention all that new
server-side functionality we have to play with. If youâve worked with any of
the modern JavaScript libraries, though, youâve experienced much of the
functionality that goes into Node, at least when it comes to asynchronous
development.
For instance, if youâve used a timer in JavaScript, youâve used an
asynchronous function. If youâve ever developed in Ajax, youâve used an
asynchronous function. Even the plain old onclick
event handler is an
asynchronous function, since we never know when the user is going to click
that mouse or tap that keyboard.
Any method that doesnât block the control thread while waiting for
some event or result is an asynchronous function. When it comes to the
onclick
handling, the
application doesnât block all other application processing, waiting for that
userâs mouse clickâjust as it doesnât block all functionality while the
timer is in effect, or while waiting for the server to return from an Ajax
call.
In this chapter, weâre going to look more closely at exactly what we mean by the term asynchronous control. In particular, weâre going to look at some asynchronous design patterns, as well as explore some of the Node modules that provide finer control over program flow when weâre working in this new ...
Get Learning Node now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.