@@ -30,22 +30,34 @@ That's it. A `Future` is anything that can be *polled* — asked "are you done y
3030``` mermaid
3131sequenceDiagram
3232 participant E as Executor
33- participant F as Future
34- participant R as Resource (I/O)
35-
36- E->>F: poll(cx)
37- F->>R: Check: is data ready?
38- R-->>F: Not yet
39- F->>R: Register waker from cx
40- F-->>E: Poll::Pending
41-
42- Note over R: ... time passes, data arrives ...
43-
44- R->>E: waker.wake() — "I'm ready!"
45- E->>F: poll(cx) — try again
46- F->>R: Check: is data ready?
47- R-->>F: Yes! Here's the data
48- F-->>E: Poll::Ready(data)
33+ participant F as Future (Task)
34+ participant OS as Operating System<br/>(e.g., epoll/kqueue)
35+ participant R as Reactor (Runtime)
36+
37+ E->>F: Calls poll(cx)
38+ Note right of F: Future attempts operation
39+ F->>OS: Syscall (e.g., read TCP socket)
40+ OS-->>F: Returns Error: Not Ready
41+
42+ F->>R: Registers: (Waker)
43+ F-->>E: Returns Poll::Pending
44+ Note left of E: Task is moved out<br/>of run queue
45+
46+ E->>E: (Executor runs other tasks OR sleeps)
47+ R->>OS: epoll_wait() / Polls OS for events
48+
49+ Note right of OS: (Sometime Later) New data arrives
50+ OS-->>R: Wakes Reactor: data is NOW READY
51+
52+ R->>R: Reactor finds Waker
53+ R->>E: Calls Waker::wake()
54+ Note right of E: Task is pushed back<br/>to Executor's run queue
55+
56+ E->>F: Calls poll(cx) again
57+ Note right of F: Future attempts operation again
58+ F->>OS: Syscall (e.g., read TCP socket)
59+ OS-->>F: Success: Returns Data Buffer
60+ F-->>E: Returns Poll::Ready(Data)
4961```
5062
5163Let's break down each piece:
0 commit comments