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(); }
public override void Invoke() { #if XBOX Future.Complete(WorkItem.Method.Invoke(WorkItem.Target, Arguments)); #else Future.Complete(WorkItem.DynamicInvoke(Arguments)); #endif }
public void FullfilShouldCallComlete() { bool called = false; m_future.Complete(() => { called = true; }); m_promise.Fulfill(33); Assert.That(called); }
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); }
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; } }
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(); }
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); }
void Completed(IFuture f) { if (f.Failed) { _CompletionSignal.Fail(f.Error); } else { _CompletionSignal.Complete(); } }
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); }
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); }
void ITaskResult.CompleteFuture(IFuture future) { var stronglyTyped = future as Future <T>; if (stronglyTyped != null) { CompleteFuture(stronglyTyped); } else { future.Complete(_Value); } }
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)); } }
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(); } }); }
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(); }); }
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); } }
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; } }
public void CompleteFuture(IFuture future) { future.Complete(_Value); }
public override void Invoke() { Future.Complete(WorkItem.DynamicInvoke(Arguments)); }
void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future) { future.Complete(); }
void ISchedulable.Schedule(TaskScheduler scheduler, IFuture future) { _Future = scheduler.Start(_Task, _ExecutionPolicy); future.Complete(_Future); }