public async Task Tasks_queued_to_the_synchronization_context_do_not_leak_to_other_threads() { var threadIds = new ConcurrentBag <int>(); using (SchedulerContext.Establish()) { await RunTasksAndCollectThreadIds(threadIds); } threadIds.Distinct().Count().Should().Be(1); }
protected async Task ExecuteAsync() { if (_budget.IsExceeded) { return; } using (SchedulerContext.Establish(_budget)) { await Task.Yield(); await ExecuteAsync(_budget); } }
public async Task Tasks_queued_on_other_threads_do_not_leak_to_the_synchronization_context() { var synchronizedThreadIds = new ConcurrentBag <int>(); var unsynchronizedThreadIds = new ConcurrentBag <int>(); var synchronized = Task.Run(async() => { using (SchedulerContext.Establish()) { await RunTasksAndCollectThreadIds(synchronizedThreadIds); } }); await Task.WhenAll( synchronized, RunTasksAndCollectThreadIds(unsynchronizedThreadIds), RunTasksAndCollectThreadIds(unsynchronizedThreadIds), RunTasksAndCollectThreadIds(unsynchronizedThreadIds)); synchronizedThreadIds.Should() .NotContain(unsynchronizedThreadIds); }
public async Task Return_values_of_executed_tasks_are_correctly_returned() { using (SchedulerContext.Establish()) { (string value, int threadId)[] ts =