Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c161dfe
chore(github issue): fit with nodejs.dev
AugustinMauroy Jan 24, 2023
507ea02
Merge branch 'main' into main
Jan 25, 2023
8071ea8
Merge branch 'main' into main
Feb 5, 2023
3d1bc0a
doc: announce Feb security release (#5042)
mhdawson Feb 7, 2023
cb1e39c
fix banner start date for security release announce (#5043)
mhdawson Feb 7, 2023
d548a3c
docs(security): typo-squirting => typosquatting (#5044)
ferdnyc Feb 12, 2023
9476a8c
doc: share new target for security releases (#5047)
mhdawson Feb 14, 2023
5006544
doc: update banner for new security release date (#5048)
mhdawson Feb 14, 2023
3cc96a6
Blog: v14.21.3 release post (#5051)
richardlau Feb 16, 2023
f745585
Blog: v16.19.1 release post (#5052)
richardlau Feb 16, 2023
7dbb7c1
Blog: v18.14.1 release post (#5054)
RafaelGSS Feb 16, 2023
7ea374d
Blog: v19.6.1 release post (#5053)
RafaelGSS Feb 16, 2023
6469baf
doc: update security annouce for binaries ready (#5055)
mhdawson Feb 16, 2023
96525c8
blog: release notes for v19.7.0 and v18.14.2 (#5064)
MylesBorins Feb 21, 2023
adade26
doc: fix typos in security release announcement (#5056)
tniessen Feb 22, 2023
abe8aa9
fix(docs): misspelled words (#5049)
CodytTorgerson Feb 27, 2023
903c1c6
ru:replace jargon in Russian text (#5027)Co-authored-by: Claudio Wund…
gurugray Feb 27, 2023
78c1867
doc: added example for Readable stream back-pressure (#5066)Co-author…
RishabhKodes Feb 27, 2023
7315680
ru: correct translation for index.md (#5045)Co-authored-by: Alexandr …
KruASe76 Feb 27, 2023
5f9862c
Blog: v18.15.0 release post (#5073)
juanarbol Mar 7, 2023
ec1ebcc
feat(infra): migrate to next.js infrastructure (#4991)Co-authored-by:…
ovflowd Mar 8, 2023
93407da
chore(i18n): removed unused hebrew language (#5074)
ovflowd Mar 8, 2023
80dbb74
chore(readme): add nodejs logo
AugustinMauroy Mar 8, 2023
f79046b
Merge branch 'main' of https://github.com/AugustinMauroy/nodejs.org
AugustinMauroy Mar 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc: added example for Readable stream back-pressure (#5066)Co-author…
…ed-by: Claudio Wunder <[email protected]>

* added example for back-pressure

Signed-off-by: Rishabh Bhandari <[email protected]>

* linting fixes

Signed-off-by: Rishabh Bhandari <[email protected]>

---------

Signed-off-by: Rishabh Bhandari <[email protected]>
Co-authored-by: Claudio Wunder <[email protected]>
  • Loading branch information
RishabhKodes and ovflowd authored Feb 27, 2023
commit 78c18677d109abc889f56c2fe133c70343c364ce
32 changes: 32 additions & 0 deletions locale/en/docs/guides/backpressuring-in-streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,38 @@ readable.on('data', (data) =>
);
```

Here's an example of using [`.push()`][] with a Readable stream.

```javascript
const { Readable } = require('stream');

// Create a custom Readable stream
const myReadableStream = new Readable({
objectMode: true,
read(size) {
// Push some data onto the stream
this.push({ message: 'Hello, world!' });
this.push(null); // Mark the end of the stream
}
});

// Consume the stream
myReadableStream.on('data', (chunk) => {
console.log(chunk);
});

// Output:
// { message: 'Hello, world!' }
```
In this example, we create a custom Readable stream that pushes a single object
onto the stream using [`.push()`][]. The [`._read()`][] method is called when the stream is ready
to consume data, and in this case, we immediately push some data onto the stream and
mark the end of the stream by pushing null.

We then consume the stream by listening for the 'data' event and logging each chunk of
data that is pushed onto the stream. In this case, we only push a single chunk of data
onto the stream, so we only see one log message.

## Rules specific to Writable Streams

Recall that a [`.write()`][] may return true or false dependent on some
Expand Down