public IFuture Start(ISchedulable schedulable) { var f = Scheduler.Start(schedulable, TaskExecutionPolicy.RunAsBackgroundTask); OwnedFutures.Add(f); return(f); }
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); }
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); }
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); }
public void BasicTest() { var future = Scheduler.Start(TaskReturn5()); Scheduler.Step(); Assert.AreEqual(5, future.Result); }
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(); } }); }
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); } }
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); }
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(); } }); }
public override void Start(TaskScheduler scheduler) { scheduler.Start(this.Talk(), TaskExecutionPolicy.RunAsBackgroundTask); }
public virtual void Start(TaskScheduler scheduler) { scheduler.Start(this.Run(), TaskExecutionPolicy.RunAsBackgroundTask); }
void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future) { _Future = scheduler.Start(_Task, _ExecutionPolicy); future.Complete(_Future); }
void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future) { _CompletionSignal = future; scheduler.Start(_Future, _Thunk, _ExecutionPolicy); }
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)); }
public static EventSubscriber New(TaskScheduler scheduler, Func <EventInfo, IEnumerator <object> > task) { return((e) => scheduler.Start(task(e), TaskExecutionPolicy.RunAsBackgroundTask)); }