Asynchronous control flow with streams
Going through the examples that we presented so far, it should be clear that streams can be useful not only to handle I/O, but also as an elegant programming pattern that can be used to process any kind of data. But the advantages do not end at the simple appearance; streams can also be leveraged to turn asynchronous control flow into flow control, as we will see in this section.
Sequential execution
By default, streams will handle data in a sequence, for example, a _transform()
function of a Transform
stream will never be invoked again with the next chunk of data, until the previous invocation completes by executing callback()
. This is an important property of streams, crucial for processing each chunk in ...
Get Node.js Design Patterns 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.