Repository navigation
feat: add the async pull adapter with cancellation on early exit - #533
Merged
Merged
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]>
awatson1978
added a commit
that referenced
this pull request
Sep 30, 2026
Kept in-branch rather than as a GitHub issue for now. Finding 13 is marked fixed (#533) and the fromPart10Stream budget question is recorded as resolved by the granted waiver (#538). Co-Authored-By: Claude Fable 5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
This adds the pull half of the hybrid contract, together with the fix for review finding 13. The contract so far is push-only: a generator calls listener methods directly.
createEventAsyncIterable, new insrc/eventStream/asyncIterator.js, is the adapter for consumers who'd rather pull. You hand it a function that drives a listener, and it gives you an async iterable you canfor awaitover. Each yielded event is a plain{ type, args }object, wheretypeis a vocabulary method name like"value"or"startSequence".The backpressure is real, not decorative. The adapter installs a drain gate on the listener, so once the internal queue passes
highWaterMark, the producer suspends at its next checkpoint until the consumer catches up.That
breakis why this PR also carries the finding-13 fix, and why the adapter was held out of #530 until now. The iterator the original code returned had noreturn()method — the hook JavaScript calls when you break out of afor awaitloop or leave it via an exception. Without it, a producer suspended in its drain gate would wait forever for a consumer that was already gone. With a stream source, it would also have left the underlying reader locked.The fix is the
return()implementation you can see at the bottom ofasyncIterator.js: it marks the iteration cancelled, drops the queue, and rejects the producer's pending drain promise with anEventIterationCancellederror. The run handler recognizes that specific rejection as a clean end of iteration rather than a stream failure, so nothing surfaces as a spurious error.The regression test in
test/eventStream/asyncIterator.test.jsdrives a 50-element dataset through ahighWaterMarkof 2, breaks after the first event, and asserts the producer settles. I verified it in both directions: it fails against the unfixed code and passes here. The other tests in the suite check that the pulled event sequence and payloads match exactly what the push core receives.🤖 Generated with Claude Code