public void Run(IValueAsyncFiber fiber) { using AutoResetEvent wait = new AutoResetEvent(false); using (fiber) { int i = 0; ValueTask AsyncHandler() { i++; if (i == OperationsPerInvoke) { wait.Set(); } return(new ValueTask()); } for (int j = 0; j < OperationsPerInvoke; j++) { fiber.Enqueue(AsyncHandler); } WaitHandle.WaitAny(new WaitHandle[] { wait }); } }
public IDisposable Schedule(IValueAsyncFiber fiber, Func <ValueTask> action, TimeSpan dueTime) { if (dueTime.TotalMilliseconds <= 0) { ValueAsyncPendingAction pending = new ValueAsyncPendingAction(action); fiber.Enqueue(pending.Execute); return(pending); } return(new ValueAsyncTimerAction(fiber, action, dueTime)); }
private void ExecuteOnTimerThread(IValueAsyncFiber fiber) { if (_interval.Ticks == TimeSpan.FromMilliseconds(-1).Ticks || _cancelled) { fiber.Remove(this); DisposeTimer(); } if (!_cancelled) { fiber.Enqueue(Execute); } }