public async Task <ProducerResponse> Send(CommandProducer command, IProducerProxy proxy) { Task <BaseCommand>?responseTask = null; using (await _lock.Lock()) { _producerManager.Outgoing(command, proxy); var baseCommand = command.AsBaseCommand(); responseTask = _requestResponseHandler.Outgoing(baseCommand); var sequence = Serializer.Serialize(baseCommand); await _stream.Send(sequence); } var response = await responseTask; if (response.CommandType == BaseCommand.Type.Error) { _producerManager.Remove(command.ProducerId); response.Error.Throw(); } return(new ProducerResponse(command.ProducerId, response.ProducerSuccess.ProducerName)); }
public async Task <ProducerResponse> Send(CommandProducer command, IChannel channel) { Task <ProducerResponse>?responseTask = null; using (await _lock.Lock()) { var baseCommand = command.AsBaseCommand(); var requestResponseTask = _requestResponseHandler.Outgoing(baseCommand); responseTask = _channelManager.Outgoing(command, requestResponseTask, channel); var sequence = Serializer.Serialize(baseCommand); await _stream.Send(sequence); } return(await responseTask); }
public async Task <ProducerResponse> Send(CommandProducer command, IChannel channel, CancellationToken cancellationToken) { ThrowIfDisposed(); Task <ProducerResponse>?responseTask; using (await _lock.Lock(cancellationToken).ConfigureAwait(false)) { var baseCommand = command.AsBaseCommand(); var requestResponseTask = _requestResponseHandler.Outgoing(baseCommand); responseTask = _channelManager.Outgoing(command, requestResponseTask, channel); var sequence = Serializer.Serialize(baseCommand); await _stream.Send(sequence).ConfigureAwait(false); } return(await responseTask.ConfigureAwait(false)); }
public Task <ProducerResponse> Outgoing(CommandProducer command, IChannel channel) { var producerId = _producerChannels.Add(channel); command.ProducerId = producerId; var response = _requestResponseHandler.Outgoing(command); return(response.ContinueWith(result => { if (result.Result.CommandType == BaseCommand.Type.Error) { _ = _producerChannels.Remove(producerId); result.Result.Error.Throw(); } channel.Connected(); return new ProducerResponse(producerId, result.Result.ProducerSuccess.ProducerName); }, TaskContinuationOptions.OnlyOnRanToCompletion)); }