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); }
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); }
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); }