[Repo Assist] feat: add TaskSeq.toChannelAsync and TaskSeq.ofChannel for System.Threading.Channels integration#416
Draft
github-actions[bot] wants to merge 2 commits intomainfrom
Conversation
…tegration, closes #415 - TaskSeq.toChannelAsync: writes all elements of a TaskSeq to a ChannelWriter<'T>, then marks the writer complete. On exception, completes the writer with the exception so downstream readers observe it. - TaskSeq.ofChannel: creates a TaskSeq<'T> from a ChannelReader<'T>, yielding elements as they become available. The sequence ends naturally when the channel is completed and fully drained, using the 'while! reader.WaitToReadAsync()' pattern. - Adds System.Threading.Channels 8.0.0 package reference to the library (needed for netstandard2.1; built-in to net5.0+). This is the only new dependency. - 29 new tests in TaskSeq.ToXXX.Tests.fs covering empty/non-empty sequences, null argument guards, round-trip correctness, side-effect semantics, and completion. All 5280 tests pass (5258 pre-existing + 29 new + 2 skipped). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
24 tasks
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 is an automated pull request from Repo Assist, an AI assistant.
Closes #415.
Summary
Adds two new functions to bridge
TaskSeqwithSystem.Threading.Channels:TaskSeq.toChannelAsyncTaskSeq<'T>to aChannelWriter<'T>, then marks the writer completeTaskSeq.ofChannelTaskSeq<'T>from aChannelReader<'T>, yielding elements as they become availableThese enable natural producer/consumer patterns with BCL channels — for example writing results from an async sequence pipeline directly into a
Channel<'T>for parallel consumption, or turning a channel into a composableTaskSeq.Implementation
toChannelAsync writer source— iteratessourceusing the standardwhile! e.MoveNextAsync()enumerator pattern and callswriter.WriteAsyncfor each element. On normal completion it callswriter.TryComplete(); on exception it callswriter.TryComplete(exn)so downstream readers observe the failure.ofChannel reader— uses the idiomatic channels drain loop:WaitToReadAsync()returnsfalsewhen the channel is completed and empty, ending the sequence naturally.New dependency
System.Threading.Channels 8.0.0is added to the library fsproj. This package is owned by Microsoft/dotnetframework (1.4 billion downloads) and provides theSystem.Threading.Channelsnamespace fornetstandard2.1consumers. Fornet5.0+consumers the package is a no-op (the types are already built in). This is the minimal addition needed to expose the channel API surface.Tests
29 new xUnit tests in
TaskSeq.ToXXX.Tests.fscovering:ofChannelterminates naturally when channel is completed and drainedtoChannelAsyncTest Status
✅ Build succeeded (Release)
✅
dotnet fantomas . --check— no formatting issues✅ All 5280 tests pass (5258 pre-existing + 29 new; 2 real-world tests remain skipped as before)