Practice · 3 of 3
Diagnose the ValueTask bug
CHALLENGE
Difficulty: advanced+25 XP
ValueTask has strict rules: await it exactly once, never await after consuming, never await concurrently. Implement static async ValueTask<int> SafeDouble(ValueTask<int> source) CORRECTLY: await the source once and return the result times 2. Then implement static async Task<int> BrokenDouble(ValueTask<int> source) that demonstrates the forbidden pattern — await it twice (var a = await source; var b = await source; return a + b;). The test runs the BROKEN one against a ValueTask backed by an IValueTaskSource created via ManualResetValueTaskSourceCore to prove it throws/misbehaves.
Press Submit to check your solution.
Back to lesson: Practice: Async drills