Skip to content

Blog post alpha 2 #1134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions _posts/2018-07-30-futures-0.3.0-alpha.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
layout: post
title: "Futures 0.3.0-alpha.2"
author: "Josef Brandl"
author_github: "MajorBreakfast"
date: 2018-07-30
categories: blog
---

`0.3.0-alpha.2` requires a recent nightly (2018-07-29 or newer):
```sh
$ rustup update
```

## What's new?

### Refined definition for "task"

The documentation for the [`Executor`](https://doc.rust-lang.org/nightly/std/task/trait.Executor.html) 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 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 "task executor" or often just "executor".

### `Try` impl for `Poll`

`Poll<Result<T, E>>` now implements the [`Try`](https://doc.rust-lang.org/std/ops/trait.Try.html) trait. This means you can now do this:

```rust
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:

```rust
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](https://github.com/rust-lang/rust/pull/52721).

### Changes to futures-rs

We revived the [changelog](https://github.com/rust-lang-nursery/futures-rs/blob/master/CHANGELOG.md)!

No major changes happened to the futures crate since the last release. There were, however, numerous little changes. Take a look at the [changelog](https://github.com/rust-lang-nursery/futures-rs/blob/master/CHANGELOG.md) 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](https://github.com/rust-lang-nursery/futures-rs/pull/1119) and the [issue](https://github.com/rust-lang-nursery/net-wg/issues/26) in the net-wg repository.
18 changes: 18 additions & 0 deletions _sass/_post.scss
Original file line number Diff line number Diff line change
@@ -57,6 +57,24 @@ article.post {
margin-bottom: 10px;
}
}

blockquote {
color: #666;
font-style: italic;
margin: 0 0 0 30px;
position: relative;
&::before {
content: "";
display: block;
position: absolute; top: 0; left: -15px; bottom: 0; width: 3px;
border-radius: 1.5px;
background: $primary-color;
}
}

ul ul {
margin-bottom: 7px;
}
}

.edit-link-container {
2 changes: 1 addition & 1 deletion _sass/futures-theme.scss
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ $primary-color: #F03E0E;

body {
font-family: Roboto;
line-height: 1.35em;
line-height: 1.42em;
}

h1, h2, h3, h4, h5, h6 {