Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
            public async ETTask WaitAsync()
            {
                --this.count;
                if (this.count < 0)
                {
                    return;
                }

                if (this.count == 0)
                {
                    List <ETTaskCompletionSource> t = this.tcss;
                    this.tcss = null;
                    foreach (ETTaskCompletionSource ttcs in t)
                    {
                        ttcs.SetResult();
                    }

                    return;
                }

                ETTaskCompletionSource tcs = new ETTaskCompletionSource();

                tcss.Add(tcs);
                await tcs.Task;
            }
Ejemplo n.º 4
0
        public void Run(bool isTimeout)
        {
            ETTaskCompletionSource <bool> tcs = this.Callback;

            this.GetParent <TimerComponent>().Remove(this.Id);
            tcs.SetResult(isTimeout);
        }
Ejemplo n.º 5
0
        public async ETTask <bool> WaitAsync(long time)
        {
            long tillTime = TimeHelper.Now() + time;
            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();
            OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource <bool> >(this, tcs);

            this.timers[timer.Id] = timer;
            AddToTimeId(tillTime, timer.Id);
            return(await tcs.Task);
        }
Ejemplo n.º 6
0
        public async ETTask <CoroutineLock> Wait(CoroutineLockType coroutineLockType, long key)
        {
            CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType];

            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
            {
                queue = EntityFactory.Create <CoroutineLockQueue>(this.Domain);
                coroutineLockQueueType.Add(key, queue);

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

            ETTaskCompletionSource <CoroutineLock> tcs = new ETTaskCompletionSource <CoroutineLock>();

            queue.Enqueue(tcs);
            return(await tcs.Task);
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
 public void Enqueue(ETTaskCompletionSource <CoroutineLock> tcs)
 {
     this.queue.Enqueue(tcs);
 }
Ejemplo n.º 9
0
 public ETTask(ETTaskCompletionSource awaiter)
 {
     this.awaiter = awaiter;
 }
Ejemplo n.º 10
0
 public override void Awake(OnceWaitTimer self, ETTaskCompletionSource <bool> callback)
 {
     self.Callback = callback;
 }