Code RoomPending task not cancelled
HardPrep Room Coding #1656

Pending task not cancelled

Code reviewConcurrencySenior–Staff~28 min

Review this Python asyncio helper that races two coroutines and returns the first result.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 28 min
Mark a line and say what kind of problem it is.0 findings
1import asyncio
2 
3async def first_of(coro_a, coro_b):
4 task_a = asyncio.create_task(coro_a)
5 task_b = asyncio.create_task(coro_b)
6 done, pending = await asyncio.wait(
7 [task_a, task_b], return_when=asyncio.FIRST_COMPLETED
8 )
9 return done.pop().result()
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.