public Task CompleteAsync() { if (onResponseStreamEnd != null) { return(writer.CompleteAsync().ContinueWith(x => onResponseStreamEnd())); } return(writer.CompleteAsync()); }
public async Task RunSample() { AsyncClientStreamingCall <GatherRequest, GatherResponse> streaming = client.Gather(); IClientStreamWriter <GatherRequest> streamWriter = streaming.RequestStream; while (true) { Console.WriteLine("Write a name to add to the list (press Enter to finish)"); string input = Console.ReadLine(); if (!string.IsNullOrEmpty(input)) { Console.WriteLine($"Streaming name '{input}' to server"); await streamWriter.WriteAsync(new() { Msg = input }); Console.WriteLine("Name successfully streamed to server"); Console.WriteLine(); } else { break; } } await streamWriter.CompleteAsync(); Console.WriteLine("Submitting data to server..."); GatherResponse response = await streaming.ResponseAsync; Console.WriteLine("Server responded: "); Console.WriteLine(response.Result); }
/// <summary> /// Writes the specified requests and send a completion. /// </summary> /// <typeparam name="TRequest">The type of the request.</typeparam> /// <param name="streamWriter"></param> /// <param name="requests">The requests.</param> /// <returns></returns> public static async Task WriteRequestsAndCompleteAsync <TRequest>(this IClientStreamWriter <TRequest> streamWriter, IEnumerable <Task <TRequest> > requests) { foreach (Task <TRequest> request in requests) { await streamWriter.WriteAsync(await request.ConfigureAwait(false)).ConfigureAwait(false); } await streamWriter.CompleteAsync().ConfigureAwait(false); }
public static IDisposable Write <T>(this IObservable <T> source, IClientStreamWriter <T> writer) { return(SubscribeAsync(source, onNext: writer.WriteAsync, onError: ex => { }, onCompleted: () => writer.CompleteAsync())); }
public override async ValueTask DisposeAsync() { if (await DisposeBase()) { await requestStream.CompleteAsync(); duplexStream?.Dispose(); } }
public async Task CompleteAsync() { if (_completed) { return; } await _clientStreamWriter.CompleteAsync().ConfigureAwait(false); _completed = true; }
internal void WriteTo(IClientStreamWriter <T> writer) { writer.WriteOptions = WriteOptions; Task task = Message == null?writer.CompleteAsync() : writer.WriteAsync(Message); task.ContinueWith(t => { _continuation?.Invoke(t); PropagateTaskResult(t, CompletionSource); }); }
/// <summary> /// Writes all elements from given enumerable to the stream. /// Completes the stream afterwards unless close = false. /// </summary> public static async Task WriteAllAsync <T>(this IClientStreamWriter <T> streamWriter, IEnumerable <T> elements, bool complete = true) where T : class { foreach (var element in elements) { await streamWriter.WriteAsync(element).ConfigureAwait(false); } if (complete) { await streamWriter.CompleteAsync().ConfigureAwait(false); } }
private async Task Start(CancellationToken token) { await foreach (var i in _request.WithCancellation(token).ConfigureAwait(false)) { await _stream.WriteAsync(new Message <TRequest>(i)).ConfigureAwait(false); } if (!token.IsCancellationRequested) { await _stream.CompleteAsync().ConfigureAwait(false); } }
private async Task ListServices(IClientStreamWriter <ServerReflectionRequest> req, ListServiceResponse resp) { var services = resp.Service.Where(p => !p.Name.StartsWith("grpc.")); foreach (var service in services) { await req.WriteAsync(new ServerReflectionRequest() { FileContainingSymbol = service.Name }); } await req.CompleteAsync(); }
private static async Task WriteStream(IClientStreamWriter <PostForecastRequest> requestStream) { await foreach (var f in ForecastFactory.CreateMultipleAsync(10)) { await requestStream.WriteAsync(new PostForecastRequest { Date = f.date, TemperatureC = f.temperatureC, Summary = f.summary, CanYouPlayGolf = f.canYouPlayGolf }); } await requestStream.CompleteAsync(); }
public void TryCloseRequestStream(IClientStreamWriter <TRequest> requestStream) { try { requestStream.CompleteAsync(); } catch (Exception ex) { if (Log.IsFinestEnabled) { Log.Finest($"{this.GetType().Name}: Error encountered closing gRPC request channel: {ex}"); } } }
private void StopRecording() { if (_waveIn != null) { OnDebug?.Invoke("Stop Recording"); _waveIn.StopRecording(); _waveIn.Dispose(); _waveIn = null; OnAssistantStateChanged?.Invoke(AssistantState.Processing); OnDebug?.Invoke("Send Request Complete"); _requestStreamAvailable = false; _requestStream.CompleteAsync(); } }
public async Task TextRequestAssistant(string request) { AsyncDuplexStreamingCall <AssistRequest, AssistResponse> assist = embeddedAssistantClient.Assist(); requestStream = assist.RequestStream; responseStream = assist.ResponseStream; currentAudioResponse.Clear(); currentTextResponse = ""; await requestStream.WriteAsync(GetConfigRequest(request)); await requestStream.CompleteAsync(); await WaitForResponse(); }
public async ValueTask DisposeAsync() { if (disposed) { return; } disposed = true; cancellationTokenSource.Cancel(); await await receivingLoopTask; await requestStream.CompleteAsync(); duplexStream?.Dispose(); }
/// <summary> /// /// </summary> /// <returns></returns> async Task IClientStreamWriter <TRequest> .CompleteAsync() { Stopwatch watch = Stopwatch.StartNew(); try { await m_Target.CompleteAsync().ConfigureAwait(false); } finally { GrpcPerformanceListener.GetMilliseconds(watch); } if (m_OnCompleted != null) { m_OnCompleted(); } }
public static async Task WriteRequestAsync(IClientStreamWriter <HelloMessage.HelloMessageRequest> requestStream) { while (true) { await Task.Yield(); Console.WriteLine("Enter a message"); var message = Console.ReadLine(); if (message.Equals("exit", StringComparison.OrdinalIgnoreCase)) { break; } await requestStream.WriteAsync(new HelloMessage.HelloMessageRequest() { Name = message }); } await requestStream.CompleteAsync(); Console.WriteLine("request complete"); }
public Task CompleteAsync() { return(inner.CompleteAsync()); }
public void Dispose() { _requestStream.CompleteAsync().GetAwaiter().GetResult(); }
public IObservable <Unit> CompleteAsync() { return(inner.CompleteAsync()); }
/// <summary> /// /// </summary> /// <returns></returns> public Task CompleteAsync() { return(m_StreamWriter.CompleteAsync()); }
/// <inheritdoc/> public async Task <bool> Connect(TConnectArguments connectArguments, CancellationToken cancellationToken) { ThrowIfConnecting(); lock (_connectLock) { ThrowIfConnecting(); _connecting = true; } var streamingCall = _establishConnection(); _clientToServer = streamingCall.RequestStream; _serverToClient = streamingCall.ResponseStream; var callContext = new ReverseCallArgumentsContext { ExecutionContext = _executionContextManager.Current.ToProtobuf(), PingInterval = Duration.FromTimeSpan(_pingInterval) }; _setArgumentsContext(connectArguments, callContext); var message = new TClientMessage(); _setConnectArguments(message, connectArguments); await _clientToServer.WriteAsync(message).ConfigureAwait(false); using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); linkedCts.CancelAfter(_pingInterval.Multiply(3)); try { if (await _serverToClient.MoveNext(linkedCts.Token).ConfigureAwait(false)) { var response = _getConnectResponse(_serverToClient.Current); if (response != null) { _logger.Trace("Received connect response"); ConnectResponse = response; _connectionEstablished = true; return(true); } else { _logger.Warning("Did not receive connect response. Server message did not contain the connect response"); } } else { _logger.Warning("Did not receive connect response. Server stream was empty"); } await _clientToServer.CompleteAsync().ConfigureAwait(false); return(false); } catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled) { if (cancellationToken.IsCancellationRequested) { _logger.Debug("Reverse Call Client was cancelled by client while connecting"); } else { _logger.Warning("Reverse Call Client was cancelled by server while connecting"); } return(false); } }