Repository navigation
Return Task from TextWriter.WriteAsync/WriteLineAsync(ReadOnlyMemory<char>) - #640
Merged
Merged
Conversation
This was referenced Oct 12, 2026
This was referenced Oct 13, 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.
Bug
The polyfills for
TextWriter.WriteAsync(ReadOnlyMemory<char>, CancellationToken)andTextWriter.WriteLineAsync(ReadOnlyMemory<char>, CancellationToken)returnedValueTask. The BCL methods returnTask(checked in the netcoreapp2.1, netstandard2.1 and net11 reference assemblies). Code such asTask t = writer.WriteAsync(memory);,Task.WhenAll(writer.WriteAsync(memory), ...)or.ContinueWith(...)compiled against the BCL but not against the polyfill, and because of the return type the polyfills were only available whenSystem.Threading.Tasks.Extensionswas referenced.Fix
Task.FeatureValueTask;FeatureMemoryis enough.Task.FromCanceled) instead of throwing synchronously, which is what the BCL does and what the neighbouringWriteAsync(string, CancellationToken)polyfill already does.Coverage
TextWriterWriteMemoryAsyncReturnsTaskassigns the results toTask(does not compile against the old signatures).TextWriterWriteMemoryAsyncCancelledasserts a pre-cancelled token yields a cancelled task and writes nothing.Consume.csassigns both overloads toTaskand no longer requiresFeatureValueTaskfor them.api_list.include.mdregenerated.Note: this is a source-breaking change for callers that stored the result in a
ValueTask.