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

            OwnedFutures.Add(f);
            return(f);
        }
示例#2
0
文件: Util.cs 项目: jli94/Fracture
        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);
        }
示例#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);
        }
示例#4
0
文件: Util.cs 项目: 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);
        }
示例#5
0
        public void BasicTest()
        {
            var future = Scheduler.Start(TaskReturn5());

            Scheduler.Step();
            Assert.AreEqual(5, future.Result);
        }
示例#6
0
文件: Util.cs 项目: jli94/Fracture
 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();
         }
     });
 }
示例#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);
     }
 }
示例#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);
        }
示例#9
0
文件: Util.cs 项目: jli94/Fracture
        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();
                }
            });
        }
示例#10
0
 public override void Start(TaskScheduler scheduler)
 {
     scheduler.Start(this.Talk(), TaskExecutionPolicy.RunAsBackgroundTask);
 }
示例#11
0
 public virtual void Start(TaskScheduler scheduler)
 {
     scheduler.Start(this.Run(), TaskExecutionPolicy.RunAsBackgroundTask);
 }
示例#12
0
文件: Util.cs 项目: jli94/Fracture
 void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
 {
     _Future = scheduler.Start(_Task, _ExecutionPolicy);
     future.Complete(_Future);
 }
示例#13
0
文件: Util.cs 项目: jli94/Fracture
 void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
 {
     _CompletionSignal = future;
     scheduler.Start(_Future, _Thunk, _ExecutionPolicy);
 }
示例#14
0
文件: Util.cs 项目: jli94/Fracture
 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));
 }
示例#15
0
文件: Util.cs 项目: jli94/Fracture
 public static EventSubscriber New(TaskScheduler scheduler, Func <EventInfo, IEnumerator <object> > task)
 {
     return((e) =>
            scheduler.Start(task(e), TaskExecutionPolicy.RunAsBackgroundTask));
 }