File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
apps/site/pages/en/learn/modules Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -557,6 +557,20 @@ class MyReadable extends Readable {
557
557
}
558
558
```
559
559
560
+ Here is an example of good practice, where the ` Readable ` stream respects backpressure by checking the return value of ` this.push() ` :
561
+
562
+ ``` js
563
+ class MyReadable extends Readable {
564
+ _read (size ) {
565
+ let chunk;
566
+ let canPushMore = true ;
567
+ while (canPushMore && null !== (chunk = getNextChunk ())) {
568
+ canPushMore = this .push (chunk);
569
+ }
570
+ }
571
+ }
572
+ ```
573
+
560
574
Additionally, from outside the custom stream, there are pitfalls to ignoring
561
575
backpressure. In this counter-example of good practice, the application's code
562
576
forces data through whenever it is available (signaled by the
You can’t perform that action at this time.
0 commit comments