Exemplo n.º 1
0
        public async Task ScheduledTaskFiresOnTime(bool scheduleFromExecutor)
        {
            var         scheduler    = new DefaultEventExecutor(); // SingleThreadEventExecutor(null, TimeSpan.FromMinutes(1))
            var         promise      = new DefaultPromise();
            Func <Task> scheduleFunc = () => scheduler.ScheduleAsync(() => promise.Complete(), TimeSpan.FromMilliseconds(100));
            Task        task         = scheduleFromExecutor ? await scheduler.SubmitAsync(scheduleFunc) : scheduleFunc();

            await Task.WhenAny(task, Task.Delay(TimeSpan.FromMilliseconds(300)));

            Assert.True(task.IsCompleted);
        }
Exemplo n.º 2
0
        public async Task ScheduledTaskFiresOnTimeWhileBusy()
        {
            var    scheduler       = new DefaultEventExecutor();
            var    promise         = new DefaultPromise();
            Action selfQueueAction = null;

            selfQueueAction = () =>
            {
                if (!promise.Task.IsCompleted)
                {
                    scheduler.Execute(selfQueueAction);
                }
            };

            scheduler.Execute(selfQueueAction);
            Task task = scheduler.ScheduleAsync(() => promise.Complete(), TimeSpan.FromMilliseconds(100));
            await Task.WhenAny(task, Task.Delay(TimeSpan.FromSeconds(1)));

            Assert.True(task.IsCompleted);
        }