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); }
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); }
public override void Awake(OnceWaitTimer self, TaskCompletionSource <bool> callback) { self.Callback = callback; }