Ejemplo n.º 1
0
        public async ETTask <IResponse> Call(IRequest request)
        {
            int     rpcId   = ++RpcId;
            RpcInfo rpcInfo = new RpcInfo(request);

            this.requestCallbacks[rpcId] = rpcInfo;
            request.RpcId = rpcId;
            this.Send(request);
            return(await rpcInfo.Tcs);
        }
Ejemplo n.º 2
0
        public static async ETTask <IResponse> Call(this Session self, IRequest request)
        {
            int     rpcId   = ++Session.RpcId;
            RpcInfo rpcInfo = new RpcInfo(request);

            self.requestCallbacks[rpcId] = rpcInfo;
            request.RpcId = rpcId;
            self.Send(request);
            return(await rpcInfo.Tcs);
        }
Ejemplo n.º 3
0
        public async ETTask <IResponse> Call(IRequest request, ETCancellationToken cancellationToken)
        {
            int     rpcId   = ++RpcId;
            RpcInfo rpcInfo = new RpcInfo(request);

            this.requestCallbacks[rpcId] = rpcInfo;
            request.RpcId = rpcId;

            this.Send(request);

            void CancelAction()
            {
                if (!this.requestCallbacks.TryGetValue(rpcId, out RpcInfo action))
                {
                    return;
                }

                this.requestCallbacks.Remove(rpcId);
                Type      responseType = OpcodeTypeComponent.Instance.GetResponseType(action.Request.GetType());
                IResponse response     = (IResponse)Activator.CreateInstance(responseType);

                response.Error = ErrorCore.ERR_Cancel;
                action.Tcs.SetResult(response);
            }

            IResponse ret;

            try
            {
                cancellationToken?.Add(CancelAction);
                ret = await rpcInfo.Tcs;
            }
            finally
            {
                cancellationToken?.Remove(CancelAction);
            }
            return(ret);
        }