Exemplo n.º 1
0
        public Task WaitAsync(long time)
        {
            long          tillTime = TimeHelper.CurrentLocalMilliseconds() + time;
            var           tcs      = new TaskCompletionSource <bool>();
            OnceWaitTimer timer    = EntityFactory.CreateWithParent <OnceWaitTimer, TaskCompletionSource <bool> >(this, tcs);

            timers[timer.Id] = timer;
            AddToTimeId(tillTime, timer.Id);
            return(tcs.Task);
        }
Exemplo n.º 2
0
        public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken)
        {
            if (TimeHelper.CurrentLocalMilliseconds() > tillTime)
            {
                return(Task.CompletedTask);
            }

            var tcs = new TaskCompletionSource <bool>();

            OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, TaskCompletionSource <bool> >(this, tcs);

            timers[timer.Id] = timer;
            AddToTimeId(tillTime, timer.Id);
            cancellationToken.Register(() => { Remove(timer.Id); });
            return(tcs.Task);
        }
Exemplo n.º 3
0
 public override void Awake(OnceWaitTimer self, TaskCompletionSource <bool> callback)
 {
     self.Callback = callback;
 }