Skip to main content
InterviewHubPRO
Section Overview
Q22

Question 22 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

44%
Rust Systems & Tokio (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

How does Async Rust work under the hood (The `Future` Trait & Poll Model)?

senior LevelCode ExampleAsync & Promises

In Simple Words: Unlike Node.js or C# which use push-based event callbacks:

  • Rust uses a Pull-Based (Poll) Model:
    • An async function does zero work until its Future is actively polled:
    rust
    pub trait Future {
        type Output;
        fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>;
    }
    
    • Returns Poll::Ready(result) when done, or Poll::Pending if waiting on I/O.
  • Waker: When an I/O event completes, the OS driver triggers the Waker, signaling the runtime executor (Tokio) to poll the future again!
text
Rust Async Poll Pipeline:
[Tokio Executor] ──► Calls future.poll(cx) ──► Returns Poll::Pending
                                                     │ (Waiting on I/O)
                                                     ▼
[OS Socket Event] ──► Waker.wake() signals runtime ──► Re-poll future! ──► Returns Poll::Ready(data)