2

I am trying to asynchronously create a new AsyncUnaryCall instance that wraps the original interecepted one.

the problem is the poor design of interceptor base class which does not allow async method interceptors. (as described here: https://github.com/grpc/grpc-dotnet/issues/694)

to get the idea, here is what is want to achieve:

public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, AsyncUnaryCallContinuation<TRequest, TResponse> continuation)
{
    var result = await MyAsyncStuff(); // if we can not await, what is the alternative?

    return new AsyncUnaryCall<TResponse>(paramters);
}
Rob Goodwin
  • 2,676
  • 2
  • 27
  • 47
SHM
  • 1,896
  • 19
  • 48

1 Answers1

0
    public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, AsyncUnaryCallContinuation<TRequest, TResponse> continuation)
    {
        var response = continuation(request, context);
        var task = MyAsyncStuff(response);
        return new AsyncUnaryCall<TResponse>(task, response.ResponseHeadersAsync, response.GetStatus, response.GetTrailers, response.Dispose);
    }

    private async Task<TResponse> MyAsyncStuff<TResponse>(AsyncUnaryCall<TResponse> responseAsync)
    {
        return await responseAsync;
    }

related discussion

Bonuspunkt
  • 21
  • 2