예제 #1
0
        public async ETTask <bool> WaitTillAsync(long tillTime, ETCancellationToken cancellationToken)
        {
            if (TimeHelper.Now() > tillTime)
            {
                return(true);
            }
            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();
            OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource <bool> >(this, tcs);

            this.timers[timer.Id] = timer;
            AddToTimeId(tillTime, timer.Id);

            long instanceId = timer.InstanceId;

            cancellationToken.Register(() =>
            {
                if (instanceId != timer.InstanceId)
                {
                    return;
                }

                timer.Run(false);

                this.Remove(timer.Id);
            });
            return(await tcs.Task);
        }
예제 #2
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);
        }
예제 #3
0
 public override void Awake(OnceWaitTimer self, ETTaskCompletionSource <bool> callback)
 {
     self.Callback = callback;
 }