We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Using Coroutines

We've used the await keyword a few times in this course. Now it's time to understand what's happening under the hood.

await pauses the current coroutine until the awaited coroutine (or other awaitable) finishes and returns a value. It lets Python switch to other work instead of blocking.

When to Use await

You can only use the await keyword:

  1. Inside an async def function.
  2. At top‑level in Pyodide (the browser's event loop is already running).

Assignment

Similar to before, the update_task_status function takes a task id, current status and completed state and returns a coroutine.

On line 5, call update_task_status with inputs:

Then await the returned coroutine and save the returned value in a variable called message which will be logged to the console (which is already written on line 9).