Пример #1
0
 void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
 {
     _Future = future;
     _Scheduler = scheduler;
     _Future.RegisterOnDispose(this.OnDisposed);
     QueueStep();
 }
Пример #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);
        }
Пример #3
0
            public void OnCompleted(Action continuation)
            {
                var oc = Registration.OnComplete(continuation);

                Future.RegisterOnComplete(oc);
                Future.RegisterOnDispose((f) => oc(f));
            }
Пример #4
0
        void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
        {
            if (future == null)
                throw new ArgumentNullException("future");

            _Future = future;
            _Scheduler = scheduler;
            _Future.RegisterOnDispose(this.OnDisposed);
            QueueStep();
        }
Пример #5
0
        void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
        {
            if (future == null)
            {
                throw new ArgumentNullException("future");
            }

            _Future    = future;
            _Scheduler = scheduler;
            _Future.RegisterOnDispose(this.OnDisposed);
            QueueStep();
        }
Пример #6
0
        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);
        }
Пример #7
0
 public static void BindFuture(this tTask task, IFuture future)
 {
     task.GetAwaiter().OnCompleted(() => {
         // FIXME: ExceptionDispatchInfo?
         if (task.IsFaulted)
         {
             future.Fail(task.Exception.InnerExceptions.Count == 1 ? task.Exception.InnerException : task.Exception);
         }
         else
         {
             future.Complete();
         }
     });
     future.RegisterOnDispose((_) => {
         task.TryCancelScope();
     });
 }
Пример #8
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();
                }
            });
        }
Пример #9
0
        public static void BindFuture(this tTask task, IFuture future)
        {
            if (task.IsCompleted && !task.IsFaulted)
            {
                future.Complete();
                return;
            }

            task.ConfigureAwait(false).GetAwaiter().OnCompleted(() => {
                // FIXME: ExceptionDispatchInfo?
                if (task.IsFaulted)
                {
                    future.Fail(task.Exception.InnerExceptions.Count == 1 ? task.Exception.InnerException : task.Exception);
                }
                else
                {
                    future.Complete();
                }
            });
            future.RegisterOnDispose(CancelScopeForTask, task);
        }
Пример #10
0
 void SetWakeConditionAndSubscribe(IFuture f, bool discardingResult)
 {
     SetWakeCondition(f, discardingResult);
     f.RegisterOnComplete(_QueueStepOnComplete);
     f.RegisterOnDispose(_QueueStepOnDispose);
 }
Пример #11
0
 void SetWakeConditionAndSubscribe(IFuture f, bool discardingResult)
 {
     SetWakeCondition(f, discardingResult);
     f.RegisterOnComplete(_QueueStepOnComplete);
     f.RegisterOnDispose(_QueueStepOnDispose);
 }
Пример #12
0
 public void RegisterOnDispose(OnDispose handler)
 {
     _SendFuture.RegisterOnDispose(handler);
 }