Code Room
Code reviewHardcr-g020
Subject Context cancellationLevel Senior–Staff~28 minCommon in Concurrency interviewsIndustries Software development

Question

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.

Talk through your review
Code to reviewpython
import asyncio async def first_of(coro_a, coro_b):    task_a = asyncio.create_task(coro_a)    task_b = asyncio.create_task(coro_b)    done, pending = await asyncio.wait(        [task_a, task_b], return_when=asyncio.FIRST_COMPLETED    )    return done.pop().result()
Run or narrate your approach, then ask the coach.