Futures need to be polled to completion. This is the job of an executor.
Some futures additionally need to wait for events from the kernel for example to know when there might be data ready to read from a file.
A reactor handles this (by using mio or polling) to register for events from the kernel and know when things might be able to progress.
std::future is the core futures functionality needed to implement async/await
std::future::Future is a trait representing an asyncronous computation.
The core method of future,
poll, attemps to resolve the future into a final
value. This method does not block if the value is not ready. Instead, the
current task is scheduled to be woken up when it's possible to make further
progress by polling again.
poll function returns:
When the future has finished, clients should not
When using a future, you generally won't
poll directy, but instead
The context passed to the
poll method can provide a
Waker, which is a handle
for waking up the current task if it is not ready.
When future is not ready yet, poll returns
Poll::Pending and stores a clone of
Waker copied from the current
Waker is then woken once
the future can make progress.
Futures alone are inert; they must be actively
polled to make progress,
meaning that each time the current task is woken up, it should actively re-poll
pending futures that it still has interest in.
futures-rs is a crate which adds utility and abstraction over futures:
FutureExt, TryFutureExt, Stream, StreamExt, TryStreamExt, Sink, SinkExt.
Tokio brings an async runtime and some additional utility to interact with
environment in async way: IO, time, unix signals, sync primitives.
Tokio is built over
Has an executor and a reactor bundled within it.
Futures that rely on the
tokio::io/fs need to be run inside the context of a
tokio runtime (which makes the tokio reactor available to them and allows
Brings an API very similar to standard lib, but for async programming. Somehow like futures-rs and tokio merged together.
Uses a different executor than tokio.
A small and fast async runtime implemented around
Doesn't come with a reactor itself.
Has a compatibility layer to interact withh tokio-based libraries.
proudly self-hosted on a cheap Raspberry Pi 2