Skip to content

Commit 7aa7759

Browse files
GKJCJGtargos
authored andcommitted
doc: clarify role of writable.cork()
The syntax of the sentence describing the role of writable.cork() was unclear. This rephrase aims to make the distinction between writing to the buffer and draining immediately to the underlying destination clearer - while keeping performance considerations clearly in mind. PR-URL: #30442 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Denys Otrishko <[email protected]>
1 parent e45edab commit 7aa7759

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

doc/api/stream.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,16 @@ The `writable.cork()` method forces all written data to be buffered in memory.
355355
The buffered data will be flushed when either the [`stream.uncork()`][] or
356356
[`stream.end()`][stream-end] methods are called.
357357

358-
The primary intent of `writable.cork()` is to avoid a situation where writing
359-
many small chunks of data to a stream do not cause a backup in the internal
360-
buffer that would have an adverse impact on performance. In such situations,
361-
implementations that implement the `writable._writev()` method can perform
362-
buffered writes in a more optimized manner.
363-
364-
See also: [`writable.uncork()`][].
358+
The primary intent of `writable.cork()` is to accommodate a situation in which
359+
several small chunks are written to the stream in rapid succession. Instead of
360+
immediately forwarding them to the underlying destination, `writable.cork()`
361+
buffers all the chunks until `writable.uncork()` is called, which will pass them
362+
all to `writable._writev()`, if present. This prevents a head-of-line blocking
363+
situation where data is being buffered while waiting for the first small chunk
364+
to be processed. However, use of `writable.cork()` without implementing
365+
`writable._writev()` may have an adverse effect on throughput.
366+
367+
See also: [`writable.uncork()`][], [`writable._writev()`][stream-_writev].
365368

366369
##### `writable.destroy([error])`
367370
<!-- YAML

0 commit comments

Comments
 (0)