Readable Streams: Simplified Construction and Iterables

Learn how to implement simple custom streams using the simplified construction approach.

Simplified construction

For simple custom streams, we can avoid creating a custom class by using the Readable stream’s simplified construction approach. With this approach, we only need to invoke new Readable(options) and pass a method named read() in the set of options. The read() method here has exactly the same semantic as the _read() method that we saw in the class extension approach. Let's rewrite our RandomStream using the simplified constructor approach.

Get hands-on with 1200+ tech skills courses.