Skip to content

[API Proposal]: PipeStream.WaitForPipeDrainAsync(CancellationToken cancellationToken) #72593

@Symbai

Description

@Symbai

Background and motivation

Currently WaitForPipe() is blocking the thread. Adding an async version with support for timeout let us better handle situations where the client cannot or has not read all remaining bytes within an expected duration. I.e. network failure or delay or client has been shut down etc.

API Proposal

namespace System.IO.Pipes

public abstract class PipeStream : Stream
{
    public Task WaitForPipeDrainAsync(CancellationToken cancellationToken);
}

API Usage

var ct = new CancellationTokenSource(3_000).Token;
try
{
    await NamedPipe.WaitForPipeDrainAsync(ct)
}
catch (OperationCanceledException e)
{
    //Retry or do something else
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.IO

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions