public Task <TReply> InvokeAsync <TRequest, TReply>(TRequest request) where TRequest : IRequest <TReply> { var invokeMethod = new InvokeMessage <TRequest, TReply>(request); if (!Publish(invokeMethod)) { invokeMethod.SetCanceled(); } return(invokeMethod.Completion); }
private bool Handle(InvokeMessage <TRequest, TReply> message) { if (!message.TryBeginHandle()) { return(false); } try { _handler.Invoke(message.Request) .ContinueWith(OnCompleted, message, TaskContinuationOptions.ExecuteSynchronously); } catch (OperationCanceledException) { message.SetCanceled(); } catch (Exception ex) { message.SetException(ex); } return(true); }
private bool Handle(InvokeMessage <TRequest, TReply> message) { if (!message.TryBeginHandle()) { return(false); } try { var result = _handler.Invoke(message.Request); message.SetResult(result); } catch (OperationCanceledException) { message.SetCanceled(); } catch (Exception ex) { message.SetException(ex); } return(true); }