-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.IO
Milestone
Description
Background and motivation
By default, when disposing a StreamReader or StreamWriter, the underlying Stream itself is disposed. Since Stream supports async disposal via IAsyncDisposable, both StreamReader and StreamWriter should implement IAsyncDisposable as well to support the case when the underlying stream supports it. Currently, only StreamWriter implements IAsyncDisposable while StreamReader doesn't, so when using StreamReader, it's only possible to dispose the underlying stream synchronously.
API Proposal
namespace System.IO;
// new
public abstract partial class TextReader : MarshalByRefObject, IDisposable, IAsyncDisposable
{
public virtual ValueTask DisposeAsync();
}
// existing
public abstract partial class TextWriter : MarshalByRefObject, IDisposable, IAsyncDisposable
{
public virtual ValueTask DisposeAsync();
}
// new
public partial class StreamReader : TextReader
{
public override ValueTask DisposeAsync();
}
// existing
public partial class StreamWriter : TextWriter
{
public override ValueTask DisposeAsync();
}API Usage
await using var reader = new StreamReader(myAsyncStream);Alternative Designs
No response
Risks
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.IO