Skip to main content

Practice ยท 4 of 5

Time-box a Flaky Operation

CHALLENGE
Difficulty: intermediate+25 XP

Wrap an arbitrary task with a timeout: return its result if it finishes in time, otherwise throw TimeoutException. Use Task.WhenAny + Task.Delay (or Task.WaitAsync โ€” .NET 8+). ``csharp static Task<string> WithTimeout(Task<string> work, int timeoutMs); ``

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