Repository navigation
Commit e447e75
stream: handle stream/iter pipeline aborts in one place
Every pull() pipeline handled an abort in several layers. Without a
signal, pull() created an AbortController for the consumer stopping
early; with one, an AbortController followed by AbortSignal.any() and a
reaction to every pull; and the pipeline created another AbortController
for its transforms and read its source through an abortable iterator,
which added a promise, a reaction and an iterator result to every batch.
Handle an abort in the pipeline's iterator instead. Its pending pull is
a promise of its own, which an abort rejects at once with the abort
reason, after calling the source's return() without waiting for it. The
source is read through a PipelineSource, which passes reads on as they
are, rejects them once the pipeline is aborted, and calls the source's
return() at most once. Each batch is checked against the pipeline's
abort state, as before.
This also fixes three cases. A pending pull now rejects when the signal
aborts while the pipeline waits on a transform, not only on the source.
When the signal aborts while no pull is pending, the source is now
closed, as the specification requires before the next pull. And the
pipeline's listener on the signal is now removed however the pipeline
ends.
When the consumer of pipeTo() stops early, the transforms' signal is now
aborted before the transforms are closed, as it was for pull(). pipeTo()
without a signal never stops the pipeline while a pull is pending, so
its pulls stay the promises of the reactions to the transforms' results.
For 16-byte chunks one per batch, iterating pull() with one or three
stateless transforms is 8-17% faster, piping with transforms and a
signal 5-8% faster, and iterating pull() with a signal about 1.55 times
faster, with or without a transform.
Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #66504
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>1 parent c4dfc6b commit e447e75
3 files changed
Lines changed: 365 additions & 242 deletions
File tree
- lib/internal/streams/iter
- test/parallel
0 commit comments