diff options
author | Matteo Collina <hello@matteocollina.com> | 2018-01-04 18:06:56 +0100 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-01-10 10:48:03 +0100 |
commit | 1e0f3315c77033ef0e01bb37c3d41c8e1d65e686 (patch) | |
tree | b529e81c0e3fda479f2ba69996f484490fb098ca /doc/api/stream.md | |
parent | 800caac2362e602d80b5c61fe1cb288bbcdb316a (diff) | |
download | android-node-v8-1e0f3315c77033ef0e01bb37c3d41c8e1d65e686.tar.gz android-node-v8-1e0f3315c77033ef0e01bb37c3d41c8e1d65e686.tar.bz2 android-node-v8-1e0f3315c77033ef0e01bb37c3d41c8e1d65e686.zip |
stream: always defer 'readable' with nextTick
Emit 'readable' always in the next tick, resulting in a single
call to _read() per microtick. This removes the need for the
user to implement buffering if they wanted to call this.push()
multiple times in an asynchronous fashion, as this.push() triggers
this._read() call.
PR-URL: https://github.com/nodejs/node/pull/17979
Fixes: https://github.com/nodejs/node/issues/3203
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'doc/api/stream.md')
-rw-r--r-- | doc/api/stream.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md index 10bd951505..537ac8f69c 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -747,6 +747,12 @@ The listener callback will be passed a single `Error` object. ##### Event: 'readable' <!-- YAML added: v0.9.4 +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/17979 + description: > + 'readable' is always emitted in the next tick after + .push() is called --> The `'readable'` event is emitted when there is data available to be read from @@ -1647,6 +1653,13 @@ const myReadable = new Readable({ ``` #### readable.\_read(size) +<!-- YAML +added: v0.9.4 +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/17979 + description: call _read() only once per microtick +--> * `size` {number} Number of bytes to read asynchronously @@ -1666,6 +1679,8 @@ additional data onto the queue. *Note*: Once the `readable._read()` method has been called, it will not be called again until the [`readable.push()`][stream-push] method is called. +`readable._read()` is guaranteed to be called only once within a +synchronous execution, i.e. a microtick. The `size` argument is advisory. For implementations where a "read" is a single operation that returns data can use the `size` argument to determine how |