private async Task HandleIncomingAsync(ITransportChannelOpenHeader header, ChannelMessage message) { using (message) { if (_sendCompletion.IsEntered) { _log.Trace("Skipping message because termination is in progress: {0}", header); return; } TransportChannel channel; lock (_channels) { if (_channels.ContainsKey(header.ChannelId)) { _log.Trace("Skipping message because the specified channel already exists: {0}", header); return; } _log.Trace("Creating new channel by remote request: {0}", header); channel = new TransportChannel(Id, header.ChannelId, _transportSendProcessor.Out, _headerFactory); _channels[channel.Id] = channel; channel.Completion.ContinueWithSynchronously((Action <Task, object>)OnChannelCompleted, channel).IgnoreAwait(_log); } await _incomingChannelQueue.Out.WriteAsync(channel).ConfigureAwait(false); } }
private async ValueTask <Maybe <ITransportChannel> > TryCreateChannelSafeAsync(UniqueId channelId) { TransportChannel channel; lock (_channels) { if (_sendCompletion.IsEntered) { return(Nothing.Instance); } _log.Trace("Creating new channel by local request: {0}", channelId); channel = new TransportChannel(Id, channelId, _transportSendProcessor.Out, _headerFactory); _channels[channel.Id] = channel; channel.Completion.ContinueWithSynchronously((Action <Task, object>)OnChannelCompleted, channel).IgnoreAwait(_log); } await channel.Initialized.ConfigureAwait(false); return(channel); }