Glossary · Phase 7 · Software engineering
Coroutine
A function that can pause while it waits and resume later, written with async def in Python.
async defmakes a coroutine, a function that can pause.awaitpauses it until the result is ready, letting the loop run others.asyncio.gatherstarts them all and waits for every result. The Anthropic Python SDK has anAsyncAnthropicclient for exactly this.
Try it now
Watch the ready list. Each task runs to its next yield, then goes to the back of the line. The log shows them interleaving.
Learn it properly
Concurrency and async · Do many things at once: processes, threads and the event loop. About 40 minutes.
Other terms from the same lesson
- event loop: The part of an async program that runs many tasks on one thread, switching whenever one is waiting.
- race condition: A bug where the result depends on the timing of tasks running at once, such as two updates where one gets lost.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.