Class BufferedClientStreamWriter<T> (4.8.0)

public class BufferedClientStreamWriter<T> where T : class

A wrapper around IClientStreamWriter<T> which removes the "one write at a time" restriction by buffering messages (and the completion signal) up to a given capacity.

Inheritance

object > BufferedClientStreamWriter<T>

Namespace

Google.Api.Gax.Grpc

Assembly

Google.Api.Gax.Grpc.dll

Type Parameter

Name Description
T

The type of message in the stream.

Constructors

BufferedClientStreamWriter(IClientStreamWriter<T>, int)

public BufferedClientStreamWriter(IClientStreamWriter<T> writer, int capacity)

Constructs an instance which writes to the specified writer, and with the given capacity.

Parameters
Name Description
writer IClientStreamWriter

The writer to delegate to.

capacity int

The maximum number of messages to buffer.

Methods

TryWriteAsync(T)

public Task TryWriteAsync(T message)

Writes a message to the stream, if there is enough space in the buffer and WriteCompleteAsync() hasn't already been called. The same write options will be used as for the previous message.

Parameter
Name Description
message T

The message to write.

Returns
Type Description
Task

null if the message queue is full or the stream has already been completed; otherwise, a Task which will complete when the message has been written to the stream.

TryWriteAsync(T, WriteOptions)

public Task TryWriteAsync(T message, WriteOptions options)

Writes a message to the stream, if there is enough space in the buffer and WriteCompleteAsync() hasn't already been called.

Parameters
Name Description
message T

The message to write.

options WriteOptions

The write options to use for this message.

Returns
Type Description
Task

null if the message queue is full or the stream has already been completed.

TryWriteCompleteAsync()

public Task TryWriteCompleteAsync()

Completes the stream when all buffered messages have been sent, if there is enough space in the buffer. This method can only be successfully called once, and further messages cannot be written after it has been successfully called.

Returns
Type Description
Task

null if this stream has already be completed, or if the buffer is full; otherwise a Task which will complete when the stream has finished being completed.

WriteAsync(T)

public Task WriteAsync(T message)

Writes a message to the stream, if there is enough space in the buffer and WriteCompleteAsync() hasn't already been called. The same write options will be used as for the previous message.

Parameter
Name Description
message T

The message to write.

Returns
Type Description
Task

A Task which will complete when the message has been written to the stream.

Exceptions
Type Description
InvalidOperationException

There isn't enough space left in the buffer, or the stream has been completed.

WriteAsync(T, WriteOptions)

public Task WriteAsync(T message, WriteOptions options)

Writes a message to the stream, if there is enough space in the buffer and WriteCompleteAsync() hasn't already been called.

Parameters
Name Description
message T

The message to write.

options WriteOptions

The write options to use for this message.

Returns
Type Description
Task

A Task which will complete when the message has been written to the stream.

Exceptions
Type Description
InvalidOperationException

There isn't enough space left in the buffer, or WriteCompleteAsync() has already been called.

WriteCompleteAsync()

public Task WriteCompleteAsync()

Completes the stream when all buffered messages have been sent, if there is enough space in the buffer. This method can only be successfully called once, and further messages cannot be written after it has been successfully called.

Returns
Type Description
Task

A Task which will complete when the stream has finished being completed.

Exceptions
Type Description
InvalidOperationException

This stream has already be completed, or the buffer is full