[Repo Assist] Add AsyncSeq.withCancellation (design parity with TaskSeq, #277)#278
Draft
github-actions[bot] wants to merge 2 commits intomainfrom
Draft
Conversation
Adds AsyncSeq.withCancellation, which returns a new AsyncSeq<'T> that passes the given CancellationToken to GetAsyncEnumerator, overriding whatever token would otherwise be supplied during iteration. This mirrors TaskSeq.withCancellation and is useful when consuming sequences from libraries (e.g. Entity Framework) that accept a CancellationToken through GetAsyncEnumerator. Closes #277 (partial - withCancellation addressed; further design parity investigation tracked in the issue). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 14, 2026
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 PR was created by Repo Assist, an automated AI assistant.
Summary
Adds
AsyncSeq.withCancellation, which returns a newAsyncSeq<'T>that passes a givenCancellationTokentoGetAsyncEnumerator, overriding whatever token would otherwise be supplied by the caller.This mirrors
TaskSeq.withCancellationand is part of the ongoing design-parity effort tracked in #277.Motivation
When consuming
IAsyncEnumerable<'T>sequences from external libraries (e.g. Entity Framework Core), the library often uses the token passed toGetAsyncEnumeratorfor cancellation. Previously there was no direct way to inject a specific token into anAsyncSeqpipeline.withCancellationfills this gap.Implementation
This is the same approach as
TaskSeq.withCancellation: wrap the source in a newIAsyncEnumerable<'T>that ignores the incoming token and passes the specified one instead. Simple, zero-allocation wrapper (beyond the object allocation for the interface).Changes
src/FSharp.Control.AsyncSeq/AsyncSeq.fs— implementation (inside#if !FABLE_COMPILER)src/FSharp.Control.AsyncSeq/AsyncSeq.fsi— public signature with XML-doctests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs— 4 new testsRELEASE_NOTES.md— 4.10.0 entryversion.props— bumped to 4.10.0Design Parity Research
As part of researching #277, here is a summary of the broader gap between
TaskSeqandAsyncSeq. Items in TaskSeq but missing from AsyncSeq (highest priority first):withCancellationpartition/partitionAsynccompareWith/compareWithAsynctryTailtailreturningoptionskipWhileInclusive/skipWhileInclusiveAsynctakeWhileInclusivetakeWhileInclusiveAsynctakeWhileInclusiveappendSeq/prependSeqseq<'T>collectAsynccollect(bind)delaylengthBy/lengthByAsync/lengthOrMaxinsertManyAt/removeManyAtwhere/whereAsyncfilter/filterAsyncNote:
AsyncSeqhas richer reactive/event-stream features not present inTaskSeq(observables, channels,merge/interleave,combineLatest, parallel map/iter,zapp,cache, etc.) — these are intentional additions that reflectAsyncSeq's broader use cases.Test Status
✅ Build succeeded (0 errors, pre-existing warnings only — NU1605, FS9999 for
groupByAsync, FS0044 for deprecatedtoAsyncEnum/ofAsyncEnumin existing tests).✅ All 321 tests pass (
dotnet test FSharp.Control.AsyncSeq.sln).