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 {
557557}
558558```
559559
560+ Here is an example of good practice, where the ` Readable ` stream respects backpressure by checking the return value of ` this.push() ` :
561+
562+ ``` javascript
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+
560574Additionally, from outside the custom stream, there are pitfalls to ignoring
561575backpressure. In this counter-example of good practice, the application's code
562576forces data through whenever it is available (signaled by the
You can’t perform that action at this time.
0 commit comments