

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Synchronous vs. Asynchronous
incomplete
2: Why Do We Want Async Code?
incomplete
3: Coroutines & the Event Loop
incomplete
4: Why Are Coroutines Useful?
incomplete
5: Using Coroutines
incomplete
6: Creating Coroutines
incomplete
This lesson's interactive features are locked, please to keep using them
Coroutines are Python's answer to slow I/O. When a coroutine hits a wait – network, disk, database – the event loop can switch to something else, so the rest of your code keeps running.
Typical I/O you'll await:
pyfetch())from pyodide.http import pyfetch
resp = await pyfetch("/api/boards")
data = await resp.json()
Coroutines help us perform I/O without forcing our entire program to freeze up while we wait for a response.