0.3.0-alpha.2
requires a recent nightly (2018-07-29 or newer):
$ rustup update
What’s new?
Refined definition for “task”
The documentation for the Executor
trait was updated. It now defines a “task executor” like this:
Futures are polled until completion by tasks, a kind of lightweight “thread”. A task executor is responsible for the creation of these tasks and the coordination of their execution on real operating system threads. In particular, whenever a task signals that it can make further progress via a wake-up notification, it is the responsibility of the task executor to put the task into a queue to continue executing it, i.e. polling the future in it, later.
The notable difference to before is that the term “task” no longer refers to the future that the task runs. Instead, from now on, the term “task” only refers to the concept of a lightweight thread, a kind of thread that doesn’t directly correspond to a thread provided by the operating system. This concept is sometimes also referred to as “green thread” - We, however, do not use either of these terms because they tend to cause confusion with real operating system threads. Instead, we call this concept a “task” and the thing that runs them a “task executor” or often just “executor”.
Try
impl for Poll
Poll<Result<T, E>>
now implements the Try
trait. This means you can now do this:
fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Result<T, E>> {
let poll: Poll<Result<T, E>> = self.future().poll();
let poll: Poll<T> = poll?; // Returns early if there's an error
let ok_value: T = ready!(poll); // Returns early if the value is pending
// Or short:
let ok_value = ready!(self.future().poll()?);
}
Additionally Try
was also implemented for Poll<Option<Result<T, E>>>
to make the ?
-operator useful in Stream::poll
implentations:
fn poll_next(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Option<Result<T, E>>> {
let poll: Poll<Option<Result<T, E>>> = self.stream().poll_next();
let poll: Poll<Option<T>> = poll?; // Returns early if there's an error
let ok_item: Option<T> = ready!(poll); // Returns early if the value is pending
// Or short:
let ok_item = ready!(self.stream().poll_next()?);
}
You can find additional details about this change in the pull request.
Changes to futures-rs
We revived the changelog!
No major changes happened to the futures crate since the last release. There were, however, numerous little changes. Take a look at the changelog to get an overview.
What are we currently working on?
Compatiblity layer for futures 0.1
We are currently working on an officially supported compatibility layer between 0.1
and 0.3
. This shim will make it possible to mix 0.1
futures with those from the 0.3 branch. The plan is to make it possible to use crates from the existing futures 0.1
ecosystem together with async functions and futures from the 0.3
crate. Additionally, this compatibility layer will also make it possible to gradually migrate exisiting applications and libraries to 0.3
. If you’re curious, take a look the compatibility layer PR and the issue in the net-wg repository.