public ResetTo ( int number ) : |
||
number | int | |
Résultat |
public async Task Executor_should_execute_tasks_until_disposal() { var task1Name = "task1"; var task2Name = "task2"; var countdown1 = new AsyncCountdown(task1Name, 10); var counter1 = new AsyncCounter(); var countdown2 = new AsyncCountdown(task2Name, 10); var counter2 = new AsyncCounter(); using (var executor = ContinuousTaskExecutor<string>.StartExecutor(Mock.Of<ITimeCoordinator>())) { Assert.True(executor.TryRegisterTaskFor(task1Name, (item, token) => StartTaskAsync(countdown1, counter1, token))); await countdown1.WaitAsync(_testTimeout); Assert.True(executor.TryRegisterTaskFor(task2Name, (item, token) => StartTaskAsync(countdown2, counter2, token))); await countdown2.WaitAsync(_testTimeout); // check that task 1 still works await countdown1.ResetTo(10).WaitAsync(_testTimeout); } var expected1 = counter1.Value; var expected2 = counter2.Value; await Task.Delay(200); Assert.Equal(expected1, counter1.Value); Assert.Equal(expected2, counter2.Value); }
public async Task Executor_should_continue_processing_other_tasks_when_one_finish() { var task1Name = "task1"; var task2Name = "task2"; var countdown1 = new AsyncCountdown(task1Name, 10); var task2Finished = new SemaphoreSlim(0); using (var executor = ContinuousTaskExecutor<string>.StartExecutor(Mock.Of<ITimeCoordinator>())) { executor.FinishedTaskFor += item => { if (item == task2Name) task2Finished.Release(); }; Assert.True(executor.TryRegisterTaskFor(task1Name, (item, token) => StartTaskAsync(token, b => b.WithCountdown(countdown1)))); await countdown1.WaitAsync(_testTimeout); Assert.True(executor.TryRegisterTaskFor(task2Name, (item, token) => Task.Delay(25, token))); await task2Finished.WaitAsync(_testTimeout); // check that task 1 still works await countdown1.ResetTo(10).WaitAsync(_testTimeout); } }