Skip to content

Commit 943de88

Browse files
docs(async): Allign docs and clean redaction.
1 parent 1f2d487 commit 943de88

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

docs/pages/language/async.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ title: "Async"
33
description: "Cooperative coroutines: run, sleep, frame, gather, with_timeout, cancel, receive."
44
---
55

6-
Cooperative concurrency via `async def` coroutines and `await` / `yield`. No preemption, a coroutine runs until it yields, sleeps, awaits, or returns. Single-threaded scheduler; concurrency by interleaving, not parallelism.
6+
Cooperative concurrency via `async def` coroutines and `await` / `yield`. No preemption: a coroutine runs until it yields, sleeps, awaits, or returns. Single-threaded scheduler; concurrency by interleaving, not parallelism.
77

8-
No `asyncio` module. Primitives, `run`, `sleep`, `frame`, `gather`, `with_timeout`, `cancel`, `receive`, are top-level builtins.
8+
No `asyncio` module. Primitives: `run`, `sleep`, `frame`, `gather`, `with_timeout`, `cancel`, `receive` are top-level builtins.
99

1010
```python
11-
import asyncio # ModuleNotFoundError: there is no asyncio
11+
import asyncio # ModuleNotFoundError: It was decided not to use asyncio and introduce the asynchrony within the virtual machine.
1212
```
1313

1414
```python
@@ -28,7 +28,7 @@ ok
2828

2929
A `def` body executes immediately. An `async def` body returns a coroutine value that does nothing until driven with `run` / `gather`. Only coroutines are cancellable (`cancel`) and can suspend on real time (`sleep`).
3030

31-
A plain `def` inside a coroutine (or at module top-level) can still call yielding builtins (`sleep`, `receive`, deferred host calls), the scheduler snapshots the helper's frame, suspends the call chain, re-enters the helper on resume so its return value lands at the original call site. The module body runs as an implicit coroutine, so top-level statements suspend the same way. From the caller, a sync helper that internally sleeps is indistinguishable from one that doesn't.
31+
A plain `def` inside a coroutine (or at module top-level) can still call yielding builtins (`sleep`, `receive`, deferred host calls): the scheduler snapshots the helper's frame, suspends the call chain, and re-enters the helper on resume so its return value lands at the original call site. The module body runs as an implicit coroutine, so top-level statements suspend the same way. From the caller, a sync helper that internally sleeps is indistinguishable from one that doesn't.
3232

3333
```python
3434
def routine():
@@ -37,9 +37,9 @@ def routine():
3737
async def coro():
3838
return 1
3939

40-
print(routine()) # 1
41-
print(coro()) # <coroutine> (does not run yet)
42-
print(run(coro())) # 1 (run drives it to completion)
40+
print(routine()) # 1
41+
print(coro()) # <coroutine> (does not run yet)
42+
print(run(coro())) # 1 (run drives it to completion)
4343
```
4444

4545
## Driving coroutines
@@ -61,7 +61,7 @@ print(run(square(5)))
6161

6262
## Sleeping
6363

64-
`sleep(seconds)` suspends until `seconds` of wall time pass. Without a host time hook, a virtual clock advances logically, coroutines interleave deterministically with no real wait (useful for tests).
64+
`sleep(seconds)` suspends until `seconds` of wall time pass. Without a host time hook, a virtual clock advances logically; coroutines interleave deterministically with no real wait (useful for tests).
6565

6666
```python
6767
async def task(name):
@@ -95,7 +95,7 @@ print(gather(fetch("a", 0.05), fetch("b", 0.02), fetch("c", 0.03)))
9595
['a!', 'b!', 'c!']
9696
```
9797

98-
The total wall time is `max(delays)`, not the sum, `b` and `c` overlap with `a`'s sleep.
98+
The total wall time is `max(delays)`, not the sum `b` and `c` overlap with `a`'s sleep.
9999

100100
### Errors
101101

@@ -154,11 +154,11 @@ except TimeoutError:
154154
timed out
155155
```
156156

157-
`with_timeout` evaluates the coroutine eagerly, it's a call, not an awaitable.
157+
`with_timeout` evaluates the coroutine eagerly it's a call, not an awaitable.
158158

159159
## cancel
160160

161-
`cancel(coro)` flags a registered coroutine for cancellation. On its next scheduler tick it transitions to `Cancelled` and stops. The body does not observe a `CancelledError`, cancellation is cooperative and silent.
161+
`cancel(coro)` flags a registered coroutine for cancellation. On its next scheduler tick it transitions to `Cancelled` and stops. The body does not observe a `CancelledError`; cancellation is cooperative and silent.
162162

163163
A coroutine in a tight synchronous loop without `await`/`sleep` cannot be cancelled until it yields:
164164

@@ -184,8 +184,8 @@ Both live in the built-in exception namespace and match `except` clauses normall
184184

185185
* **No preemption**, `while True: pass` inside a coroutine blocks the scheduler.
186186
* **Silent cancellation**, `cancel(coro)` stops the coro; the body doesn't see `CancelledError`. Use `with_timeout` for deadline-as-exception.
187-
* **Cooperative host loop**, scheduler suspends to the host when it can't progress synchronously (pending timer/frame/event); embedder resumes via `run_start` / `run_resume` / `run_push_event`. The legacy non-suspending `run` cannot resume, code using `sleep(n>0)`, `frame()`, or an empty `receive()` must run via the driver loop; statements after a top-level `run()` don't execute after a yield.
188-
* **`async for`** works against any `for`-iterable plus coroutines and async generators (`async def` with `yield`). Each iteration resumes to the next yield. No `__aiter__` / `__anext__` dispatch on user classes, write an `async def` generator. Behaviour over lists/tuples/dicts is identical to regular `for`.
187+
* **Cooperative host loop**, scheduler suspends to the host when it can't progress synchronously (pending timer/frame/event); embedder resumes via `run_start` / `run_resume` / `run_push_event`. The legacy non-suspending `run` cannot resume. Code using `sleep(n>0)`, `frame()`, or an empty `receive()` must run via the driver loop; statements after a top-level `run()` don't execute after a yield.
188+
* **`async for`** works against any `for`-iterable plus coroutines and async generators (`async def` with `yield`). Each iteration resumes to the next yield. No `__aiter__` / `__anext__` dispatch on user classes; write an `async def` generator instead. Behaviour over lists/tuples/dicts is identical to regular `for`.
189189
* **`async with`** reuses sync dispatch (`__enter__` / `__exit__`); `__aenter__` / `__aexit__` aren't consulted. For async setup/teardown, use `try` / `finally` with explicit `await`.
190190
* **No async comprehensions**, `[x async for x in it]` unsupported.
191191
* **No `gen.send` / `throw` / `close`**, generators and coroutines are one-way producers. For bidirectional flow, use `run` / `gather` and pass messages via args.

0 commit comments

Comments
 (0)