예제 #1
0
        internal void CompleteWithResult(ITaskResult result)
        {
            if (CheckForDiscardedError())
            {
                return;
            }

            if (_Future == null)
            {
                if (result == null)
                {
                    // Disposed without result
                    return;
                }
                else
                {
                    // FIXME: is this right?
                    // Disposed with result but nowhere to send it.
                    return;
                }
            }
            else if (result != null)
            {
                _Future.Complete(result.Value);
            }
            else
            {
                _Future.Complete(null);
            }

            Dispose();
        }
예제 #2
0
        public override void Invoke()
        {
#if XBOX
            Future.Complete(WorkItem.Method.Invoke(WorkItem.Target, Arguments));
#else
            Future.Complete(WorkItem.DynamicInvoke(Arguments));
#endif
        }
예제 #3
0
        public void FullfilShouldCallComlete()
        {
            bool called = false;

            m_future.Complete(() => {
                called = true;
            });

            m_promise.Fulfill(33);

            Assert.That(called);
        }
예제 #4
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);
        }
예제 #5
0
        static void DispatchNewMessage(Peer from, string message)
        {
            _MessageBuilder.Remove(0, _MessageBuilder.Length);
            if (from != null)
            {
                _MessageBuilder.Append("<");
                _MessageBuilder.Append(from);
                _MessageBuilder.Append("> ");
                _MessageBuilder.Append(message);
            }
            else
            {
                _MessageBuilder.Append("*** ");
                _MessageBuilder.Append(message);
            }

            Messages.Add(new Message {
                From = from, Text = message, DisplayText = _MessageBuilder.ToString()
            });

            if (Messages.Count > MaxMessagesToStore)
            {
                int numToRemove = MaxMessagesToStore / 2;
                Messages.RemoveRange(0, numToRemove);
                MessageIdBase += numToRemove;
            }

            if (WaitingForMessages != null)
            {
                WaitingForMessages.Complete();
                WaitingForMessages = null;
            }
        }
예제 #6
0
        internal void QueueSleep(long completeWhen, IFuture future)
        {
            if (_IsDisposed)
            {
                return;
            }

            long now = TimeProvider.Ticks;

            if (now > completeWhen)
            {
                using (IsActive)
                    future.Complete();

                return;
            }

            SleepItem sleep = new SleepItem {
                Until = completeWhen, Future = future
            };

            lock (_SleepWorker.WorkItems)
                _SleepWorker.WorkItems.Enqueue(sleep);
            _SleepWorker.Wake();
        }
예제 #7
0
        public void YieldOnFutureTest()
        {
            this.TestFuture = new Future <object>();
            var future = Scheduler.Start(TaskReturnValueOfFuture());

            Scheduler.Step();
            Assert.IsFalse(future.Completed);
            TestFuture.Complete(10);
            Scheduler.Step();
            Assert.AreEqual(10, future.Result);
        }
예제 #8
0
파일: Util.cs 프로젝트: jli94/Fracture
 void Completed(IFuture f)
 {
     if (f.Failed)
     {
         _CompletionSignal.Fail(f.Error);
     }
     else
     {
         _CompletionSignal.Complete();
     }
 }
예제 #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
파일: 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);
        }
예제 #11
0
        void ITaskResult.CompleteFuture(IFuture future)
        {
            var stronglyTyped = future as Future <T>;

            if (stronglyTyped != null)
            {
                CompleteFuture(stronglyTyped);
            }
            else
            {
                future.Complete(_Value);
            }
        }
예제 #12
0
파일: Util.cs 프로젝트: jli94/Fracture
        void HandleResult(IFuture wait)
        {
            var errors = (from f in _Futures where f.Failed select f.Error).ToArray();

            if (errors.Length == 0)
            {
                _ResultFuture.Complete();
            }
            else
            {
                _ResultFuture.Fail(new WaitForAllException(errors));
            }
        }
예제 #13
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();
         }
     });
 }
예제 #14
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();
     });
 }
예제 #15
0
        public bool Tick(long now)
        {
            long ticksLeft = Math.Max(Until - now, 0);

            if (ticksLeft == 0)
            {
                try {
                    Future.Complete();
                } catch (FutureAlreadyHasResultException ex) {
                    if (ex.Future != Future)
                    {
                        throw;
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #16
0
파일: Util.cs 프로젝트: jli94/Fracture
        internal void ReadyForMore()
        {
            if (_SequenceFuture.Completed)
            {
                Dispose();
                return;
            }

            lock (_Buffer)
                if (_Buffer.Count == 0)
                {
                    Dispose();
                }
                else
                {
                    _Buffer.Clear();
                }

            if (_ReadyForMoreFuture != null)
            {
                _ReadyForMoreFuture.Complete();
                _ReadyForMoreFuture = null;
            }
        }
예제 #17
0
 public void CompleteFuture(IFuture future)
 {
     future.Complete(_Value);
 }
예제 #18
0
 public override void Invoke()
 {
     Future.Complete(WorkItem.DynamicInvoke(Arguments));
 }
예제 #19
0
파일: Util.cs 프로젝트: jli94/Fracture
 void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
 {
     future.Complete();
 }
예제 #20
0
파일: Util.cs 프로젝트: jli94/Fracture
 void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future)
 {
     _Future = scheduler.Start(_Task, _ExecutionPolicy);
     future.Complete(_Future);
 }