# Class AsyncResponseStream&lt;TResponse&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.AsyncResponseStream-1)
- [4.8.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.8.0/Google.Api.Gax.Grpc.AsyncResponseStream-1)
- [4.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.4.0/Google.Api.Gax.Grpc.AsyncResponseStream-1)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.3.1/Google.Api.Gax.Grpc.AsyncResponseStream-1)
- [4.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.2.0/Google.Api.Gax.Grpc.AsyncResponseStream-1)
- [4.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.0.0/Google.Api.Gax.Grpc.AsyncResponseStream-1)
- [3.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/3.2.0/Google.Api.Gax.Grpc.AsyncResponseStream-1)

    public sealed class AsyncResponseStream<TResponse> : IAsyncEnumerable<TResponse>, IAsyncEnumerator<TResponse>, IAsyncDisposable

An adapter from the gRPC stream representation ([IAsyncStreamReader\<T\>](https://github.com/grpc/grpc-dotnet/blob/7c43ddb5d68008782dc0dba2d0feaa3ed91a9fb2/src/Grpc.Core.Api/IAsyncStreamReader.cs)) to [IAsyncEnumerable\<T\>](https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerable-1)
and [IAsyncEnumerator\<T\>](https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerator-1). Note that [GetAsyncEnumerator(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.AsyncResponseStream-1#Google_Api_Gax_Grpc_AsyncResponseStream_1_GetAsyncEnumerator_System_Threading_CancellationToken_) can only
be called once per instance due to the "only iterate once" nature of the response stream.

## Inheritance

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

## Implements

[IAsyncEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerable-1), [IAsyncEnumerator](https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerator-1), [IAsyncDisposable](https://learn.microsoft.com/dotnet/api/system.iasyncdisposable)

## 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.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** |
| `TResponse` | The response type. |

## Remarks

This type implements both of the standard asynchronous sequence interfaces for simplicity of use:

- C# 8 users can use `await foreach` because it implements [IAsyncEnumerable\<T\>](https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerable-1)
- It's compatible with the System.Linq.Async package for query transformations.
- Pre-C# 8 users who will be calling [MoveNextAsync()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.AsyncResponseStream-1#Google_Api_Gax_Grpc_AsyncResponseStream_1_MoveNextAsync) and [Current](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.AsyncResponseStream-1#Google_Api_Gax_Grpc_AsyncResponseStream_1_Current) directly don't need to call [GetAsyncEnumerator(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.AsyncResponseStream-1#Google_Api_Gax_Grpc_AsyncResponseStream_1_GetAsyncEnumerator_System_Threading_CancellationToken_).

<br />

## Properties

### Current

    public TResponse Current { get; }

Gets the element in the collection at the current position of the enumerator.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `TResponse` |   |

## Methods

### DisposeAsync()

    public ValueTask DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or
resetting unmanaged resources asynchronously.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask` |   |

### GetAsyncEnumerator(CancellationToken)

    public IAsyncEnumerator<TResponse> GetAsyncEnumerator(CancellationToken cancellationToken = default)

Begins iterating over the response stream, using the specified cancellation token. This method can only be called
once per instance.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The cancellation token to use in subsequent [MoveNextAsync()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.AsyncResponseStream-1#Google_Api_Gax_Grpc_AsyncResponseStream_1_MoveNextAsync) calls. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerator-1` | An iterator over the response stream. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | This method has already been called on this instance. |

### MoveNextAsync()

    public ValueTask<bool> MoveNextAsync()

Moves to the next item, using the cancellation token configured by [GetAsyncEnumerator(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.AsyncResponseStream-1#Google_Api_Gax_Grpc_AsyncResponseStream_1_GetAsyncEnumerator_System_Threading_CancellationToken_).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask-1https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### MoveNextAsync(CancellationToken)

    public ValueTask<bool> MoveNextAsync(CancellationToken cancellationToken)

Moves to the next item, using the specified cancellation token.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The cancellation token to use for this step. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask-1https://learn.microsoft.com/dotnet/api/system.boolean` | A task that will complete with a result of true if the enumerator was successfully advanced to the next element, or false if the enumerator has passed the end of the collection. |