public Task<ResponseData> Request(RequestData request, CancellationToken token) { this.EnsureIsRunning(); var requestId = this.NextId(); var callback = new TaskCompletionSource<ResponseData>(); this.requestCallbacks[requestId] = callback; Task.Run(() => { var zmqRequest = new ZmqRequest(requestId, request); var zmqRequestBytes = zmqRequest.ToBinary(); this.requestsQueue.TryAdd(zmqRequestBytes); }); if (token != CancellationToken.None) { token.Register(() => { TaskCompletionSource<ResponseData> _; this.requestCallbacks.TryRemove(requestId, out _); }); } return callback.Task; }
public Task <ResponseData> Request(RequestData request, CancellationToken token) { this.EnsureIsRunning(); var requestId = this.NextId(); var callback = new TaskCompletionSource <ResponseData>(); this.requestCallbacks[requestId] = callback; Task.Run(() => { var zmqRequest = new ZmqRequest(requestId, request); var zmqRequestBytes = zmqRequest.ToBinary(); this.requestsQueue.TryAdd(zmqRequestBytes); }); if (token != CancellationToken.None) { token.Register(() => { TaskCompletionSource <ResponseData> _; this.requestCallbacks.TryRemove(requestId, out _); }); } return(callback.Task); }