Skip to main content

Practice · 3 of 5

Cooperative Cancellation

CHALLENGE
Difficulty: intermediate+25 XP

Implement a worker that honors cancellation: it processes items one at a time, checks the token BEFORE each item, and returns how many it completed. When cancelled mid-way, throw OperationCanceledException with the token. ``csharp static Task<int> ProcessAsync(IEnumerable<int> items, Func<int, Task> work, CancellationToken ct); ``

Back to lesson: Practice: Async Practice: Fetch, Fan-out, Cancel