# Class BufferedClientStreamWriter&lt;T&gt; (4.10.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [4.10.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1)
- [4.8.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.8.0/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1)
- [4.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.4.0/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.3.1/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1)
- [4.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.2.0/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1)
- [4.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.0.0/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1)
- [3.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/3.2.0/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1)

    public class BufferedClientStreamWriter<T> where T : class

A wrapper around [IClientStreamWriter\<T\>](https://github.com/grpc/grpc-dotnet/blob/7c43ddb5d68008782dc0dba2d0feaa3ed91a9fb2/src/Grpc.Core.Api/IClientStreamWriter.cs) which removes the "one write at a time"
restriction by buffering messages (and the completion signal) up to a given capacity.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> BufferedClientStreamWriter\<T\>

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Api.Gax.Grpc](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/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` | `https://github.com/grpc/grpc-dotnet/blob/7c43ddb5d68008782dc0dba2d0feaa3ed91a9fb2/src/Grpc.Core.Api/IClientStreamWriter.cs` The writer to delegate to. |
| `capacity` | `https://learn.microsoft.com/dotnet/api/system.int32` 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()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1#Google_Api_Gax_Grpc_BufferedClientStreamWriter_1_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** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | `null` if the message queue is full or the stream has already been completed; otherwise, a [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.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()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1#Google_Api_Gax_Grpc_BufferedClientStreamWriter_1_WriteCompleteAsync)
hasn't already been called.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `T` The message to write. |
| `options` | `https://github.com/grpc/grpc-dotnet/blob/7c43ddb5d68008782dc0dba2d0feaa3ed91a9fb2/src/Grpc.Core.Api/WriteOptions.cs` The write options to use for this message. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.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** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | `null` if this stream has already be completed, or if the buffer is full; otherwise a [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.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()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1#Google_Api_Gax_Grpc_BufferedClientStreamWriter_1_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** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) which will complete when the message has been written to the stream. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.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()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1#Google_Api_Gax_Grpc_BufferedClientStreamWriter_1_WriteCompleteAsync)
hasn't already been called.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `T` The message to write. |
| `options` | `https://github.com/grpc/grpc-dotnet/blob/7c43ddb5d68008782dc0dba2d0feaa3ed91a9fb2/src/Grpc.Core.Api/WriteOptions.cs` The write options to use for this message. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) which will complete when the message has been written to the stream. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | There isn't enough space left in the buffer, or [WriteCompleteAsync()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.BufferedClientStreamWriter-1#Google_Api_Gax_Grpc_BufferedClientStreamWriter_1_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** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) which will complete when the stream has finished being completed. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | This stream has already be completed, or the buffer is full |