skip to content

Asynchronous Programming

Async Rust compiles async fn into state machines driven by a runtime the language does not ship. Interviewers test polling, Pin, Send futures, async traits and cancellation.

on this pageshow

explore

questions

page 2 of 2

A Rust CLI drives a Tokio-based library call with `futures::executor::block_on` and panics with "there is no reactor running"; why, and how do you fix it?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Tokio's I/O and timer types need a Tokio runtime's driver in the current context; futures' block_on is a bare executor that sets none up, so creating the timer panics. Drive the call with that runtime's own block_on.

open as a page

In Rust, why is `match topics.lock().unwrap().get(&room).cloned() { Some(t) => notify(t).await, None => {} }` not `Send`, despite cloning the value out?

level: seniorimportance: should knowfreq 40%

basics

~20 s

The MutexGuard returned by lock().unwrap() is a temporary in the match scrutinee, and such temporaries live until the match has finished. The guard is therefore still alive at notify(t).await, which makes the future not Send even though t is an owned clone.

open as a page

A Rust loop runs `while let Some(r) = set.next().await` over a `FuturesUnordered` and awaits slow work for each result; why do the set's other futures stall?

level: seniorimportance: should knowfreq 32%

basics

~10 s

A FuturesUnordered makes progress only while someone polls it. While the loop body awaits other work, nothing calls poll_next, so the remaining futures stay suspended at their current .await even after their wakers fire.

open as a page

As a Rust library lead publishing a `Storage` trait that third parties implement, used both generically and as `Box<dyn ...>` on multi-threaded executors, how would you shape its async methods?

level: principalimportance: should knowfreq 30%

basics

~20 s

Decide Send and dyn support up front; both are SemVer commitments. A common shape: methods returning impl Future + Send, plus a boxed dyn-compatible companion trait via a blanket impl; async-trait when simplicity or an old MSRV outweighs per-call allocation.

open as a page

As the lead of a Rust async service, what team rule would you set for which operations must be cancellation-safe and how cleanup is structured?

level: principalimportance: should knowfreq 28%

basics

~20 s

Require every shared async method to document its cancellation safety, let timeouts and races drop only safe ones, keep resumable state outside futures, and order effects so a drop means a retry. Async cleanup goes in explicit close methods.

open as a page

Your team is moving a Rust CLI tool and a high-traffic HTTP API to async; how do you decide which should go async at all, and on which runtime?

level: principalimportance: should knowfreq 34%

basics

~20 s

Go async where many I/O waits overlap, like the API; a sequential CLI is simpler blocking, with block_on only for async-only libraries. Pick the runtime your libraries need: Tokio for most servers, smol for small tools, Embassy on microcontrollers.

open as a page

For a latency-sensitive Rust service, how do you choose between a work-stealing multi-threaded executor requiring `Send` futures and thread-per-core local executors accepting `!Send` ones?

level: principalimportance: should knowfreq 30%

basics

~20 s

Default to a work-stealing executor with Send futures: it balances uneven load and fits most libraries. Choose thread-per-core local executors only when measurements show cross-thread synchronisation dominates and the work can be sharded evenly, accepting Rc-based state and manual balancing.

open as a page

In Rust, what does the IntoFuture trait change about .await, and why would a request builder implement it instead of Future?

level: middleimportance: nice to knowfreq 30%

basics

~20 s

Since Rust 1.64, .await first calls IntoFuture::into_future on its operand; every Future gets that for free. A builder implements IntoFuture so callers can chain settings and write .await directly, with the request future built only at that point.

open as a page

In Rust, what does the Future contract allow when poll is called again on a future that has already returned Poll::Ready?

level: seniorimportance: nice to knowfreq 20%

basics

~20 s

Almost anything except undefined behaviour: the Future docs say a second poll after Ready may panic, block forever or misbehave. Compiler-generated async futures and std's Ready panic; the futures crate's fuse() makes extra polls return Pending.

open as a page

In a hand-written Rust future combinator `CountPolls<F>` wrapping an inner future, why does `self.inner.poll(cx)` fail, and how does pin projection fix it?

level: seniorimportance: nice to knowfreq 25%

basics

~20 s

poll needs Pin<&mut F>, but Pin<&mut Self> yields neither that nor &mut self.inner when F may be !Unpin (E0599). Project the pin: pin_project! with #[pin] inner gives Pin<&mut F> for it and &mut for the rest.

open as a page

showing 31–40 of 40