Repository navigation
Harden async stream lifecycle handling - #5
Merged
Merged
Conversation
Reject invalid or non-cancellable convenience sources before pumping, distinguish successful stop from external abort failure, propagate pump errors through availability waits, and correctly stop after included untilTag values. Remove per-tag option normalization work and document the cancellable Node/Web stream contract.
Wake read-ahead pumps at buffer consumption boundaries instead of every byte increment, skip post-tag async checks when no stop callback is configured, and normalize read options only at parser entry points.
Allow late external failures to reject parsing after source settlement, interrupt pending Node reads while awaiting actual teardown, preserve synchronous and delayed close errors, cancel sources after processing failures, and restore bounded-pump wakeups for all cursor movement. Clarify the read-ahead high-water-mark and stop metadata contracts.
Serialize late failures with pump finalization, normalize reasonless source errors, await Node teardown across close-event variants, restore every cursor wakeup path, validate cancellable sources before iterator acquisition, and strengthen backpressure tests so they prove source reads are actually paused.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stop) from external workflow failure (abort(error)), preserving reasonless, source, cancellation, parser, and late external errors.untilTagwithincludeUntilTagValue: true, nestedshouldStopscoping, and source failure propagation through availability waits.emitClose: false, and synchronous/delayed_destroyerrors are preserved.readAheadHighWaterMark, directreadTagHeader()cursor behavior, andstopInfofields.Review guide
src/BufferStream.jsfor the independent failure/stop signals, serialized finalization, Node/Web adapters, close/error handling, and bounded read-ahead wakeups.src/AsyncDicomReader.jsto confirm parsing races the pump failure signal, lateabort(error)remains effective after source settlement, and direct greater-tag reads rewind consistently.test/readBufferStream.test.js; they assert the next source read is genuinely blocked until cursor advancement.test/async-data.test.jsfor pending Node reads, late abort, reasonless failures, synchronous/delayed teardown errors, andemitClose: false.Safety
readFileFromAsyncStream()accepts reliably cancellable Node streams and WebReadableStreams.BufferStream.fromAsyncStream()support for generic async iterables remains available and exposescancellable: falsewhere interruption is not guaranteed.readAheadHighWaterMarkis checked between atomic source chunks, so one source chunk may exceed the threshold.pump.abort(error)rejects pending reads; callers must still await their external processing promise because fulfilled promises cannot be retroactively rejected.Performance
Interleaved same-process benchmark against
dcmjs-org/master(81e7e11) on Node 22.14, built bundles, 11 alternating rounds,test/sample-dicom.dcm(~528 KB):The largest measured absolute difference is about 0.036 ms per file.
Test plan
360tests)360tests)emitClose: falsetoEnd(), andconcat()wakeups