private IEnumerator TestFuncTaskCoroutine() { var scheduler = new FiberTaskScheduler(); var task = new YieldableTask(() => new YieldForSeconds(2)); task.Start(scheduler); while (!task.IsCompleted) { yield return(FiberInstruction.YieldToAnyFiber); } }
public void TestInstructionInTask() { var start = DateTime.Now; using (var backgroundFiberScheduler = SystemFiberScheduler.StartNew()) { // Submit a task to the background scheduler and wait for it to complete var task = new YieldableTask(new YieldForSeconds(2)); task.RunSynchronously(new FiberTaskScheduler(backgroundFiberScheduler)); } var end = DateTime.Now; Assert.GreaterOrEqual(end - start, TimeSpan.FromSeconds(2)); Assert.LessOrEqual(end - start, TimeSpan.FromSeconds(3)); }
public void TestCancellationToken() { var start = DateTime.Now; var cancelSource = new CancellationTokenSource(); var backgroundFiberScheduler = SystemFiberScheduler.StartNew(cancelSource.Token); // Submit a task to the background scheduler and wait for it to complete var task = new YieldableTask(new YieldForSeconds(2)); task.RunSynchronously(new FiberTaskScheduler(backgroundFiberScheduler)); // Shutdown the scheduler thread cancelSource.Cancel(); backgroundFiberScheduler.SchedulerThread.Join(5000); var end = DateTime.Now; Assert.GreaterOrEqual(end - start, TimeSpan.FromSeconds(2)); Assert.LessOrEqual(end - start, TimeSpan.FromSeconds(3)); }