public ETTask WaitAsync(long time) { long tillTime = TimeHelper.Now() + time; ETTaskCompletionSource tcs = new ETTaskCompletionSource(); OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource>(this, tcs); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(tcs.Task); }
public ETTask WaitTillAsync(long tillTime, ETCancellationToken cancellationToken) { if (TimeHelper.Now() > tillTime) { return(ETTask.CompletedTask); } ETTaskCompletionSource tcs = new ETTaskCompletionSource(); OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource>(this, tcs); this.timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); cancellationToken.Register(() => { this.Remove(timer.Id); }); return(tcs.Task); }