예제 #1
0
        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 });
            }
        }
예제 #2
0
        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));
        }
예제 #3
0
        private void ExecuteOnTimerThread(IValueAsyncFiber fiber)
        {
            if (_interval.Ticks == TimeSpan.FromMilliseconds(-1).Ticks || _cancelled)
            {
                fiber.Remove(this);
                DisposeTimer();
            }

            if (!_cancelled)
            {
                fiber.Enqueue(Execute);
            }
        }