Skip to content

API Proposal: Add PipeReader.ReadAsync overloads to allow waiting for a specific amount of data #25063

@davidfowl

Description

@davidfowl

Often a protocol knows how much data it is waiting for (TLS frames being one example, size headered binary protocols being another).

Instead of ReadAsync() then you check the header and you see you don't have enough, so you ReadAsync() check if you have enough and continue doing loops until you have a complete frame. If you could do a "ReadAsync(xxxxx)" and it wouldn't return unless there was an error/complete or at least that amount of data was available it would solve extra looping in every downstream protocol

Proposed API

public abstract partial class PipeReader
{
+    public virtual ValueTask<ReadResult> ReadAsync(int minimumBytes, CancellationToken cancellationToken = default);
}

/cc @Drawaes

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions