Skip to content

Async Rust: From Futures To Production Part1 chapter2 - "Output, poll(), Context, Waker" diagram requires more detail #49

@Migorithm

Description

@Migorithm

The diagram simplifies the interplay between Executor and Reactor by lumping reactor with Resource(I/O) and Operating System.

While it'd be easier to understand for those who got to learn async rust for the first time, combining those three seem quite off.

I like to suggest the following diagram if it is not too complex

sequenceDiagram
    participant E as Executor
    participant F as Future (Task)
    participant OS as Operating System<br/>(e.g., epoll/kqueue)
    participant R as Reactor (Runtime)

    E->>F: Calls poll(cx)
    Note right of F: Future attempts operation
    F->>OS: Syscall (e.g., read TCP socket #4)
    OS-->>F: Returns Error: (Not Ready)
    
    F->>R: Registers: (Waker)

    
    F-->>E: Returns Poll::Pending
    Note left of E: Task is moved out<br/>of run queue
    

    E->>E: (Executor runs other tasks OR sleeps)
    R->>OS: epoll_wait() / Polls OS for events


    Note right of OS: (Sometime Later) New data arrives
    OS-->>R: Wakes Reactor: data is NOW READABLE
    Note over R: OS NOTIFIES REACTOR FIRST
    
    R->>R: Reactor finds Waker
    R->>E: Calls Waker::wake()
    Note right of E: Task is pushed back<br/>to Executor's run queue

    E->>F: Calls poll(cx) again
    Note right of F: Future attempts operation again
    F->>OS: Syscall (e.g., read TCP socket #4)
    OS-->>F: Success: Returns Data Buffer
    F-->>E: Returns Poll::Ready(Data)
Loading

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions