public static FuncTask Run(CancellableFunc doThis, CancellationToken cancellationToken = null, TaskScheduler scheduler = null) { var task = new FuncTask(doThis, cancellationToken, scheduler); task.Start(); return(task); }
public void FuncTask_ActionContinuation_Fact() { FuncTask task = null; ActionTask continuation = null; task = Task.Run(() => { task.HasStarted.ShouldBeTrue(); continuation.HasStarted.ShouldBeFalse(); return("task"); }); continuation = task.ContinueWith(previous => { previous.Id.ShouldEqual(task.Id); previous.IsComplete.ShouldBeTrue(); previous.Result.ShouldEqual("task"); previous.Exception.ShouldBeNull(); continuation.HasStarted.ShouldBeTrue(); }); task.ShouldNotBeNull(); continuation.ShouldNotBeNull(); task.HasStarted.ShouldBeTrue(); continuation.HasStarted.ShouldBeFalse(); //NB waiting on first task should not be required! //task1.Wait(); //task1.IsComplete.ShouldBeTrue(); continuation.Wait(); task.Status.ShouldEqual(TaskStatus.RanToCompletion); continuation.Status.ShouldEqual(TaskStatus.RanToCompletion); EnsureQuietDisposal(task); EnsureQuietDisposal(continuation); }
public void RunFuncTask_Fact() { FuncTask task = Task.Run(() => 42); task.ShouldNotBeNull(); task.HasStarted.ShouldBeTrue(); }
public static FuncTask Run(Func doThis, TaskScheduler scheduler = null) { var task = new FuncTask(doThis, scheduler); task.Start(); return(task); }
public void RunCancellableFuncTask_Fact() { FuncTask task = Task.Run(token => 42); task.ShouldNotBeNull(); task.HasStarted.ShouldBeTrue(); }
public void NewFuncTask_Fact() { FuncTask task = Task.New(() => 42); task.ShouldNotBeNull(); task.HasStarted.ShouldBeFalse(); }
public void NewCancellableFuncTask_Fact() { FuncTask task = Task.New(token => 42); task.ShouldNotBeNull(); task.HasStarted.ShouldBeFalse(); }
public FuncTask ContinueWith(CancellableContinuation.Func next, CancellationToken cancellationToken = null, TaskScheduler scheduler = null) { if (next == null) { throw new ArgumentNullException("next"); } return(FuncTask.BuildContinuation(this, token => next(this, token), cancellationToken, scheduler)); }
public FuncTask ContinueWith(BasicContinuation.Func next, TaskScheduler scheduler = null) { if (next == null) { throw new ArgumentNullException("next"); } return(FuncTask.BuildContinuation(this, token => next(this), CancellationToken.None, scheduler)); }
internal static FuncTask BuildContinuation(Task antecedent, CancellableFunc doThis, CancellationToken cancellationToken, TaskScheduler scheduler = null) { var continuation = new FuncTask(doThis, cancellationToken, scheduler); continuation.SetStatusToUnstartedContinuation(); TaskContinuationManager.RegisterContinuation(antecedent, continuation); return(continuation); }
public void FuncTask_FiresUnobservedHandler_Fact() { FuncTask task = Task.Run(token => { throw new Exception("thrown in task"); return(null); }, CancellationToken.None); var unobserved = EnsureUnobservedException(task); unobserved[0].Message.ShouldEqual("thrown in task"); }
public void FuncTask_ObserveViaWait_Fact() { FuncTask task = Task.Run(() => { throw new Exception("thrown in task"); return("we should not see this"); }); var exception = Trap.WaitException(task); exception.ShouldNotBeNull(); task.Status.ShouldEqual(TaskStatus.Faulted); task.Result.ShouldBeNull(); exception.InnerExceptionCount.ShouldEqual(1); exception[0].Message.ShouldEqual("thrown in task"); task.Exception[0].Message.ShouldEqual("thrown in task"); EnsureQuietDisposal(task); }
public void FuncTask_ObserveViaContinuation_Fact() { FuncTask task = Task.Run(() => { throw new Exception("thrown in task"); return("we should not see this"); }); ActionTask continuation = task.ContinueWith(previous => { previous.Status.ShouldEqual(TaskStatus.Faulted); var aggregateException = previous.Exception; aggregateException[0].Message.ShouldEqual("thrown in task"); }); continuation.Wait(); EnsureQuietDisposal(task); EnsureQuietDisposal(continuation); }