Skip to main content

Practice · 2 of 2

Deadline enforcement

CHALLENGE
Difficulty: advanced+25 XP

Implement static async Task<string> ReadWithDeadline(Func<Task<string>> read, TimeSpan deadline): await the read; if it exceeds the deadline, throw TimeoutException and STOP WAITING (the read task continues but the caller does not). Use Task.WhenAny(read, Task.Delay(deadline)) — the classic abandon-the-wait pattern. The test uses a read that sleeps 500ms with a 50ms deadline and expects a throw in well under 500ms.

Back to lesson: Practice: Networking drills