/// <summary> /// Gets all responses from the stream asynchronously. /// </summary> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>The collection of all row key samples.</returns> public async Task <IList <SampleRowKeysResponse> > ToListAsync( CancellationToken cancellationToken = default) { var responses = new List <SampleRowKeysResponse>(); while (await ResponseStream.MoveNext(cancellationToken).ConfigureAwait(false)) { responses.Add(ResponseStream.Current); } return(responses); }
public async Task CallAsync() { try { if (!await _call !.ResponseStream.MoveNext()) { throw new Exception("Unexpected end of stream."); } } catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled && _cts.IsCancellationRequested) { // Expected exception from canceling call } }
private async Task Subscribe() { try { while (await _call !.ResponseStream.MoveNext().ConfigureAwait(false) && !_disposed.IsCancellationRequested) { var current = _call !.ResponseStream.Current; switch (current.ContentCase) { case ReadResp.ContentOneofCase.Event: try { await _eventAppeared(this, ConvertToResolvedEvent(current), current.Event.CountCase switch { ReadResp.Types.ReadEvent.CountOneofCase.RetryCount => current.Event.RetryCount, _ => default }, _disposed.Token).ConfigureAwait(false); if (_autoAck) { await AckInternal(Uuid.FromDto(current.Event.Link?.Id ?? current.Event.Event.Id)) .ConfigureAwait(false); } } catch (Exception ex) when(ex is ObjectDisposedException || ex is OperationCanceledException) { SubscriptionDropped(SubscriptionDroppedReason.Disposed); return; } catch (Exception ex) { try { SubscriptionDropped(SubscriptionDroppedReason.SubscriberError, ex); } finally { _disposed.Cancel(); } return; } break; }