Пример #1
0
        /// <summary>
        /// Executes method after the provided delay
        /// </summary>
        public static Task <TOut> ScheduleExecution <TOut>(Func <TOut> method, HashedWheelTimer timer, int delay)
        {
            var tcs = new TaskCompletionSource <TOut>();

            timer.NewTimeout(state =>
            {
                var tcsState = (TaskCompletionSource <TOut>)state;
                try
                {
                    tcsState.SetResult(method());
                }
                catch (Exception ex)
                {
                    tcsState.SetException(ex);
                }
            }, tcs, delay);
            return(tcs.Task);
        }
Пример #2
0
 internal TimeoutItem(HashedWheelTimer timer, Action <object> action, object actionState)
 {
     _actionState = actionState;
     _action      = action;
     _timer       = timer;
 }