Solution: Asynchronous Streaming Adapter
Explore how to design an asynchronous streaming adapter that converts a legacy callback-driven file reader into a modern async iterator. Understand how to manage event-driven data flow with queues and promises to synchronize push and pull timing models, enabling clean async iteration in Node.js. This lesson equips you to integrate legacy streaming APIs with modern async code using the adapter pattern.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 4–15: We define a
legacyReaderthat reads data from a real file using Node’sfsmodule.It opens a readable stream with
fs.createReadStream(filename, { encoding: 'utf-8' }).On each
'data'event, ...