Example #1
0
        public ETTask <IResponse> Call(IRequest request)
        {
            int rpcId = ++RpcId;
            var tcs   = new ETTaskCompletionSource <IResponse>();

            this.requestCallback[rpcId] = (response) =>
            {
                if (response is ErrorResponse)
                {
                    tcs.SetException(new Exception($"Rpc error: {MongoHelper.ToJson(response)}"));
                    return;
                }

                if (ErrorCode.IsRpcNeedThrowException(response.Error))
                {
                    tcs.SetException(new Exception($"Rpc error: {MongoHelper.ToJson(response)}"));
                    return;
                }

                tcs.SetResult(response);
            };

            request.RpcId = rpcId;
            this.Send(request);
            return(tcs.Task);
        }
        public static ETTask <IActorResponse> Call(this ActorMessageSenderComponent self, long actorId, IActorRequest message, bool exception = true)
        {
            if (actorId == 0)
            {
                throw new Exception($"actor id is 0: {MongoHelper.ToJson(message)}");
            }

            var tcs = new ETTaskCompletionSource <IActorResponse>();

            int              process          = IdGenerater.GetProcess(actorId);
            string           address          = StartProcessConfigCategory.Instance.Get(process).InnerAddress;
            Session          session          = NetInnerComponent.Instance.Get(address);
            InstanceIdStruct instanceIdStruct = new InstanceIdStruct(actorId);

            instanceIdStruct.Process = IdGenerater.Process;
            message.ActorId          = instanceIdStruct.ToLong();
            message.RpcId            = ++self.RpcId;

            self.requestCallback.Add(message.RpcId, new ActorMessageSender((response) =>
            {
                if (exception && ErrorCode.IsRpcNeedThrowException(response.Error))
                {
                    tcs.SetException(new Exception($"Rpc error: {MongoHelper.ToJson(response)}"));
                    return;
                }

                tcs.SetResult(response);
            }));
            session.Send(message);

            return(tcs.Task);
        }
Example #3
0
        public void Run(bool isTimeout)
        {
            ETTaskCompletionSource <bool> tcs = this.Callback;

            this.GetParent <TimerComponent>().Remove(this.Id);
            tcs.SetResult(isTimeout);
        }
        public void Notify(CoroutineLockType coroutineLockType, long key)
        {
            CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType];

            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
            {
                throw new Exception($"first work notify not find queue");
            }
            if (queue.Count == 0)
            {
                coroutineLockQueueType.Remove(key);
                queue.Dispose();
                return;
            }

            ETTaskCompletionSource <CoroutineLock> tcs = queue.Dequeue();

            tcs.SetResult(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key));
        }