Пример #1
0
        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;
        }
Пример #2
0
        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);
        }