Skip to main content

Async checkpoint

Challenge on lesson: Checkpoint: async

CHALLENGE
Difficulty: advanced+25 XP

Implement static async ValueTask<int> ReadCachedAsync(int key, Func<int, Task<int>> slowFetch): a static ConcurrentDictionary<int,int> cache; on hit return synchronously WITHOUT awaiting (ValueTask fast path); on miss await slowFetch and store the result. Then implement static async Task<string> WithTimeout(Task<string> work, TimeSpan timeout) returning the work's result or throwing TimeoutException โ€” using CancellationTokenSource with a timeout, and cancelling the linked token.

Back to lesson: Checkpoint: async