Exemple #1
0
        protected virtual Task <TResponse> DoSend(TRequest request, int timeoutMilliseconds)
        {
            int timeout = Math.Max(timeoutMilliseconds, DEFAULT_TIMEOUT);
            TaskTimeoutOrCompletionSource <TResponse> promise = new TaskTimeoutOrCompletionSource <TResponse>(timeout);

            this.channel.WriteAsync(request).ContinueWith(t =>
            {
                if (t.IsCompleted)
                {
                    promises.TryAdd(request.Sequence.ToString(), promise);

                    idleStateMonitor?.OnSent();
                }
                else
                {
                    if (t.Exception != null)
                    {
                        promise.TrySetException(t.Exception);
                    }
                    else
                    {
                        promise.TrySetException(new IOException());
                    }
                }
            }, TaskContinuationOptions.ExecuteSynchronously);
            return(promise.Task);
        }
 protected virtual void OnSent(IMessage message)
 {
     idleStateMonitor?.OnSent();
 }