Esempio n. 1
0
        public void WaitForFirstGCTest()
        {
            var a = Scheduler.Start(InfiniteTask());
            var b = Scheduler.Start(new Sleep(2));
            var c = Future.WaitForFirst(a, b);

            while (!c.Completed)
            {
                Scheduler.Step();
                GC.Collect();
            }
            Assert.AreEqual(b, c.Result);
        }
Esempio n. 2
0
 void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
 {
     _SleepFuture = scheduler.Start(new Sleep(_Timeout));
     _TaskFuture  = Future.WaitForFirst(_Future, _SleepFuture);
     _TaskFuture.RegisterOnComplete((f) => {
         if (f.Result == _SleepFuture)
         {
             future.Fail(new TimeoutException("WaitWithTimeout timed out."));
         }
         else
         {
             future.Complete();
         }
     });
 }
Esempio n. 3
0
        public void WaitForFirstTest()
        {
            int duration  = 2;
            int timeScale = 25;

            var a = Scheduler.Start(InfiniteTask());
            var b = Scheduler.Start(new Sleep(duration));
            var c = Future.WaitForFirst(a, b);

            GC.Collect();

            long timeStart = Time.Ticks;

            c.GetCompletionEvent().Wait();
            Assert.AreEqual(b, c.Result);
            long timeEnd = Time.Ticks;

            long elapsed = (long)Math.Round(TimeSpan.FromTicks(timeEnd - timeStart).TotalSeconds *timeScale);

            Assert.AreEqual(duration * timeScale, elapsed);
        }