mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
stream: fixup stream/iter to drop at most one entry per share call
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode PR-URL: https://github.com/nodejs/node/pull/66028 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
This commit is contained in:
1 parent
7e1ae1757b
commit
dd23e9e514
3 files changed
+66
-14
No files matched your search
@@ -576,6 +576,7 @@ class SyncShareImpl {
|
||||
}
|
||||
|
||||
// Check buffer limit
|
||||
let dropped = false;
|
||||
if (self.#bufferedBytes >= self.#options.budget) {
|
||||
switch (self.#options.backpressure) {
|
||||
case 'strict':
|
||||
@@ -598,17 +599,20 @@ class SyncShareImpl {
|
||||
self.#recomputeMinCursor();
|
||||
break;
|
||||
case 'drop-newest':
|
||||
while (self.#bufferedBytes >= self.#options.budget &&
|
||||
!self.#sourceExhausted &&
|
||||
!self.#cancelled &&
|
||||
self.#sourceError === kNoShareError) {
|
||||
self.#pullFromSource(true);
|
||||
}
|
||||
// Discarding does not reclaim budget, and the slowest
|
||||
// consumer cannot advance while this synchronous next() is
|
||||
// running, so at most one entry may be dropped per call.
|
||||
// Looping here would spin forever on an unbounded source
|
||||
// and drain a finite one in a single call.
|
||||
self.#pullFromSource(true);
|
||||
dropped = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
self.#pullFromSource();
|
||||
if (!dropped) {
|
||||
self.#pullFromSource();
|
||||
}
|
||||
|
||||
if (self.#sourceError !== undefined) {
|
||||
state.detached = true;
|
||||
|
||||
Reference in new issue
Block a user