public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg) { Contract.Requires(msg != null); // todo: cancellation support //try //{ // if (!validatePromise(ctx, promise, true)) // { // ReferenceCountUtil.release(msg); // return; // } //} //catch (RuntimeException e) //{ // ReferenceCountUtil.release(msg); // throw e; //} if (this.executor.InEventLoop) { return(ChannelHandlerInvokerUtil.InvokeWriteNowAsync(ctx, msg)); } else { var promise = new TaskCompletionSource(); this.SafeExecuteOutbound(WriteTask.NewInstance(ctx, msg, promise), promise, msg); return(promise.Task); } }
Task WriteAsync(object msg, bool flush) { AbstractChannelHandlerContext next = this.FindContextOutbound(); object m = this.pipeline.Touch(msg, next); IEventExecutor nextExecutor = next.Executor; if (nextExecutor.InEventLoop) { return(flush ? next.InvokeWriteAndFlushAsync(m) : next.InvokeWriteAsync(m)); } else { var promise = new TaskCompletionSource(); AbstractWriteTask task = flush ? WriteAndFlushTask.NewInstance(next, m, promise) : (AbstractWriteTask)WriteTask.NewInstance(next, m, promise); SafeExecuteOutbound(nextExecutor, task, promise, msg); return(promise.Task); } }