Example #1
0
        public IFuture Start(ISchedulable schedulable)
        {
            var f = Scheduler.Start(schedulable, TaskExecutionPolicy.RunAsBackgroundTask);

            OwnedFutures.Add(f);
            return(f);
        }
Example #2
0
        void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
        {
            if (_Schedulables == null)
            {
                throw new InvalidOperationException();
            }
            else if (_Schedulables.Length == 0)
            {
                future.Complete();
                return;
            }

            for (int i = 0; i < _Schedulables.Length; i++)
            {
                var s = _Schedulables[i];
                if (s != null)
                {
                    _Futures[i] = scheduler.Start(s, TaskExecutionPolicy.RunWhileFutureLives);
                }
            }

            _Schedulables = null;
            _ResultFuture = future;

            _WaitFuture = Future.WaitForAll(_Futures);
            _WaitFuture.RegisterOnComplete(HandleResult);
            _WaitFuture.RegisterOnDispose(HandleDisposed);
        }
Example #3
0
        public static Future <Web.Response> IssueAsync(this HttpWebRequest request, TaskScheduler scheduler)
        {
            var f = new Future <Web.Response>();

            scheduler.Start(f, new SchedulableGeneratorThunk(Web.IssueRequest(request)), TaskExecutionPolicy.RunWhileFutureLives);
            return(f);
        }
Example #4
0
File: Util.cs Project: sq/Libraries
        void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
        {
            _Future = scheduler.Start(_Task, TaskExecutionPolicy.RunAsBackgroundTask);

            _Future.RegisterOnComplete((f) => {
                object r;
                Exception e;
                f.GetResult(out r, out e);
                future.Complete(r);
            });
            _Future.RegisterOnDispose(future.Dispose);
        }
Example #5
0
        public void BasicTest()
        {
            var future = Scheduler.Start(TaskReturn5());

            Scheduler.Step();
            Assert.AreEqual(5, future.Result);
        }
Example #6
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();
         }
     });
 }
Example #7
0
 void ScheduleNextStepForSchedulable(ISchedulable value)
 {
     if (value is WaitForNextStep)
     {
         _Scheduler.QueueWorkItemForNextStep(_QueueStep);
     }
     else if (value is Yield)
     {
         QueueStep();
     }
     else
     {
         var temp = _Scheduler.Start(value, TaskExecutionPolicy.RunWhileFutureLives);
         SetWakeConditionAndSubscribe(temp, true);
     }
 }
Example #8
0
        public void YieldStartGetTaskIterator()
        {
            var e    = CountTo100(Thread.CurrentThread);
            var iter = TaskEnumerator <int> .FromEnumerable(e, 1);

            var output = new List <int>();
            var f      = Scheduler.Start(IterationTask(iter, output));

            Scheduler.WaitFor(f);

            int[] expected = new int[100];
            for (int i = 0; i < 100; i++)
            {
                expected[i] = i;
            }

            Assert.AreEqual(output.ToArray(), expected);
        }
Example #9
0
        protected void Start()
        {
            _Thunk             = new SchedulableGeneratorThunk(_Task);
            _Thunk.OnNextValue = OnNextValue;

            _SequenceFuture = _Scheduler.Start(_Thunk, TaskExecutionPolicy.RunWhileFutureLives);
            _SequenceFuture.RegisterOnDispose((f) => {
                Resume();
                Dispose();
            });
            _SequenceFuture.RegisterOnComplete((f) => {
                if (f.Failed)
                {
                    Fail(f.Error);
                }
                else
                {
                    Resume();
                }
            });
        }
Example #10
0
 public override void Start(TaskScheduler scheduler)
 {
     scheduler.Start(this.Talk(), TaskExecutionPolicy.RunAsBackgroundTask);
 }
Example #11
0
 public virtual void Start(TaskScheduler scheduler)
 {
     scheduler.Start(this.Run(), TaskExecutionPolicy.RunAsBackgroundTask);
 }
Example #12
0
 void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
 {
     _Future = scheduler.Start(_Task, _ExecutionPolicy);
     future.Complete(_Future);
 }
Example #13
0
 void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
 {
     _CompletionSignal = future;
     scheduler.Start(_Future, _Thunk, _ExecutionPolicy);
 }
Example #14
0
 public static TypedEventSubscriber <T> New <T> (TaskScheduler scheduler, Func <EventInfo, T, IEnumerator <object> > task)
     where T : class
 {
     return((e, args) =>
            scheduler.Start(task(e, args), TaskExecutionPolicy.RunAsBackgroundTask));
 }
Example #15
0
 public static EventSubscriber New(TaskScheduler scheduler, Func <EventInfo, IEnumerator <object> > task)
 {
     return((e) =>
            scheduler.Start(task(e), TaskExecutionPolicy.RunAsBackgroundTask));
 }