public async ETTask <bool> WaitAsync(long time, ETCancellationToken cancellationToken) { long tillTime = TimeHelper.Now() + time; if (TimeHelper.Now() > tillTime) { return(true); } ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>(); OnceWaitTimer timer = TimerFactory.Create <OnceWaitTimer, ETTaskCompletionSource <bool> >(tcs); this.timers[timer.InstanceId] = timer; AddToTimeId(tillTime, timer.InstanceId); long instanceId = timer.InstanceId; cancellationToken.Register(() => { if (instanceId != timer.InstanceId) { return; } timer.Run(false); this.Remove(timer.InstanceId); }); return(await tcs.Task); }
public async ETTask <bool> WaitTillAsync(long tillTime, ETCancellationToken cancellationToken) { if (TimeHelper.Now() > tillTime) { return(true); } ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>(); OnceWaitTimer timer = Entity.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); }