Show / Hide Table of Contents

Class AsyncResponseStream<TResponse>

An adapter from the gRPC stream representation (IAsyncStreamReader<T>) to System.Collections.Generic.IAsyncEnumerable<T> and System.Collections.Generic.IAsyncEnumerator<T>. Note that GetAsyncEnumerator(CancellationToken) can only be called once per instance due to the "only iterate once" nature of the response stream.

Inheritance
System.Object
AsyncResponseStream<TResponse>
Implements
System.Collections.Generic.IAsyncEnumerable<TResponse>
System.Collections.Generic.IAsyncEnumerator<TResponse>
System.IAsyncDisposable
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Api.Gax.Grpc
Assembly: Google.Api.Gax.Grpc.dll
Syntax
public sealed class AsyncResponseStream<TResponse> : IAsyncEnumerable<TResponse>, IAsyncEnumerator<TResponse>, IAsyncDisposable
Type Parameters
Name Description
TResponse

The response type.

Remarks

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

Properties

Current

Declaration
public TResponse Current { get; }
Property Value
Type Description
TResponse
Implements
System.Collections.Generic.IAsyncEnumerator<T>.Current

Methods

DisposeAsync()

Declaration
public ValueTask DisposeAsync()
Returns
Type Description
System.Threading.Tasks.ValueTask
Implements
System.IAsyncDisposable.DisposeAsync()

GetAsyncEnumerator(CancellationToken)

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

Declaration
public IAsyncEnumerator<TResponse> GetAsyncEnumerator(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken

The cancellation token to use in subsequent MoveNextAsync() calls.

Returns
Type Description
System.Collections.Generic.IAsyncEnumerator<TResponse>

An iterator over the response stream.

Implements
System.Collections.Generic.IAsyncEnumerable<T>.GetAsyncEnumerator(System.Threading.CancellationToken)
Exceptions
Type Condition
System.InvalidOperationException

This method has already been called on this instance.

MoveNextAsync()

Moves to the next item, using the cancellation token configured by GetAsyncEnumerator(CancellationToken).

Declaration
public ValueTask<bool> MoveNextAsync()
Returns
Type Description
System.Threading.Tasks.ValueTask<System.Boolean>
Implements
System.Collections.Generic.IAsyncEnumerator<T>.MoveNextAsync()

MoveNextAsync(CancellationToken)

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

Declaration
public ValueTask<bool> MoveNextAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken

The cancellation token to use for this step.

Returns
Type Description
System.Threading.Tasks.ValueTask<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.

Back to top