Skip to content

Commit 189a10f

Browse files
committed
Fix incorrect Python async info
1 parent 3b8f9f8 commit 189a10f

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎async-book/src/ch01-why-async-is-different-in-rust.md‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ There is no built-in runtime, no thread pool, no event loop. The `async` keyword
1818

1919
```mermaid
2020
graph LR
21-
subgraph "Other Languages"
21+
subgraph "C# / JS / Go"
2222
EAGER["Eager Execution<br/>Task starts immediately"]
2323
BUILTIN["Built-in Runtime<br/>Thread pool included"]
2424
GC["GC-Managed<br/>No lifetime concerns"]
2525
end
2626
27-
subgraph "Rust"
28-
LAZY["Lazy Execution<br/>Nothing happens until polled"]
27+
subgraph "Rust (and Python*)"
28+
LAZY["Lazy Execution<br/>Nothing happens until polled/awaited"]
2929
BYOB["Bring Your Own Runtime<br/>You choose the executor"]
3030
OWNED["Ownership Applies<br/>Lifetimes, Send, Sync matter"]
3131
end
@@ -42,6 +42,8 @@ graph LR
4242
style GC fill:#e3f2fd,color:#000
4343
```
4444

45+
> \* Python coroutines are lazy like Rust futures — they don't execute until awaited or scheduled. However, Python still uses GC and has no ownership/lifetime concerns.
46+
4547
### No Built-In Runtime
4648

4749
```rust
@@ -71,13 +73,13 @@ var result = await task; // Just waits for completion
7173

7274
This is the single most important mental shift:
7375

74-
| | C# / JavaScript / Python | Go | Rust |
75-
|---|---|---|---|
76-
| **Creation** | `Task` starts executing immediately | Goroutine starts immediately | `Future` does nothing until polled |
77-
| **Dropping** | Detached task continues running | Goroutine runs until return | Dropping a Future cancels it |
78-
| **Runtime** | Built into the language/VM | Built into the binary (M:N scheduler) | You choose (tokio, smol, etc.) |
79-
| **Scheduling** | Automatic (thread pool) | Automatic (GMP scheduler) | Explicit (`spawn`, `block_on`) |
80-
| **Cancellation** | `CancellationToken` (cooperative) | `context.Context` (cooperative) | Drop the future (immediate) |
76+
| | C# / JavaScript | Python | Go | Rust |
77+
|---|---|---|---|---|
78+
| **Creation** | `Task` starts executing immediately | Coroutine is **lazy** — returns an object, doesn't run until awaited or scheduled | Goroutine starts immediately | `Future` does nothing until polled |
79+
| **Dropping** | Detached task continues running | Unawaited coroutine is garbage-collected (with a warning) | Goroutine runs until return | Dropping a Future cancels it |
80+
| **Runtime** | Built into the language/VM | `asyncio` event loop (must be explicitly started) | Built into the binary (M:N scheduler) | You choose (tokio, smol, etc.) |
81+
| **Scheduling** | Automatic (thread pool) | Event loop + `await` or `create_task()` | Automatic (GMP scheduler) | Explicit (`spawn`, `block_on`) |
82+
| **Cancellation** | `CancellationToken` (cooperative) | `Task.cancel()` (cooperative, raises `CancelledError`) | `context.Context` (cooperative) | Drop the future (immediate) |
8183

8284
```rust
8385
// To actually RUN a future, you need an executor:

0 commit comments

Comments
 (0)