Controlling readable streams


show more Controlling readable streams provides you with in-depth training on Developer. Taught by Joseph LeBlanc as part of the Node.js Essential Training (2013) show less
please wait ...

Controlling readable streams

Once a stream is created, it typically starts immediately, unless it's paused. In this video, we'll start a stream and then pause it. Let's go to the Exercise Files, load chapter 9, video 3, and then Copy these two files to the desktop. Now let's have a look at control.js. Everything in this file is the same as the previous video, except for lines 5 through 12. First we're calling the pause method of this stream. Calling stream.pause right away, will pause the stream, before any event listener's have a chance to respond to an incoming chunk.

It's also possible to pause a stream after it's already started. Any time you pause a stream, it will stay paused until you resume it. On line 7, we're just sending a message to the console saying that we're paused. Then on line 9 we're calling setTimeout. We're passing in 1,000 milliseconds, which will come out to one second, and then we have a callback function. So in this example, we're waiting one second befo...

Controlling readable streams
Video duration: 1m 52s 3h 17m Intermediate

Viewers:

Controlling readable streams provides you with in-depth training on Developer. Taught by Joseph LeBlanc as part of the Node.js Essential Training (2013)

Subject:
Developer
Software:
JavaScript Node.js
Author:
please wait ...