* Skip the write in DuplexAsyncChannel.Writer.finish when the buffer is empty
A cloned writer's finish(buffer:finalElement:) always called
write(buffer:), even with an empty buffer. Once another clone had
finished the channel, that write threw
MultiProducerSingleConsumerAsyncChannelAlreadyFinishedError, so a
second `try await finish()` failed although it had nothing to write.
This is why clonedWriterCanProduceConcurrently has failed since #459.
Only write when the buffer has elements. A clone that still has
buffered elements after the channel finished keeps throwing.
Resolves#470.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Test finishing a cloned writer through the protocol and the adapter
clonedWriterCanProduceConcurrently only covers a direct
`try await clone.finish()`. Also cover a generic CallerAsyncWriter and
asAsyncWriter(), where there is no concrete finish() overload, after
the other writer has finished. Both threw
MultiProducerSingleConsumerAsyncChannelAlreadyFinishedError before the
previous commit.
A third test checks that finishing a clone with elements still throws
once the channel has finished, so those elements are never dropped
silently.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* [AsyncStreaming] Propagate cancellation to late readers
Distinguish cancellation from normal source completion when a reader continuation is installed after the channel has already finished.
* [AsyncStreaming] Distinguish terminal read states
Track cancellation separately from an already-consumed terminal result so normal source completion does not throw CancellationError. Precondition on repeated reads after cancellation, a final element, or a source failure, with coverage for each terminal path.
* [AsyncStreaming] Handle pending reader cancellation
Deliver cancellation exactly once when it races with a resumed reader, preserve fused final-element completion, and align terminal-read tests and documentation with the reader contract.
* [AsyncStreaming] Test cancellation through public API
Remove the internal-only state-machine test so the regression suite exercises the supported AsyncStreaming interface without @testable import.
* [AsyncStreaming] Introduce a `MultiProducerSingleConsumerChannel` and a duplex
* Add tests
* Fix UnstableAsyncStreaming test build
---------
Co-authored-by: Franz Busch <f.busch@apple.com>