public async Task HandleAsync(IncomingInvocationDescriptor info, ITransportChannel channel) { var invocation = _incomingInvocationFactory.CreateAsync <TRequest, TResponse>(info, channel); try { TRequest request = default; while (await invocation.In.WaitForNextSafeAsync().ConfigureAwait(false)) { while (invocation.In.TryReadSafe(out var item)) { request = item; } } var context = new MethodCallContext(info.Source.ApplicationId, info.Source.ConnectionId); await _handler(request, invocation.Out, context).ConfigureAwait(false); invocation.Out.TryComplete(); } catch (Exception ex) { invocation.Out.TryTerminate(ex); throw; } finally { await invocation.Completion.ConfigureAwait(false); } }
public async Task HandleAsync(IncomingInvocationDescriptor info, ITransportChannel channel) { var invocation = _incomingInvocationFactory.CreateAsync <TRequest, TResponse>(info, channel); var cancellation = new CancellationTokenSource(); invocation.Completion .ContinueWithSynchronously(_ => cancellation.Cancel(), CancellationToken.None) .IgnoreAwait(); try { await invocation.StartCompletion.ConfigureAwait(false); var context = new MethodCallContext( info.Source.ApplicationId, info.Source.ApplicationInstanceId, info.Source.ConnectionId, cancellation.Token); await HandleCoreAsync(invocation, context).ConfigureAwait(false); invocation.Out.TryComplete(); } catch (Exception ex) { invocation.Out.TryTerminate(ex); invocation.In.ConsumeBufferedItems(x => { }); throw; } finally { await invocation.Completion.ConfigureAwait(false); } }