Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rationale for async blocks
  • Loading branch information
aturon committed Apr 20, 2018
commit 84c7edf0867cc6ee1eb9f5814da6ff71cca02997
29 changes: 29 additions & 0 deletions text/0000-async_await.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,35 @@ shipping - async/await syntax (a concept available widely in many languages
which interacts well with our existing async IO libraries) is the most logical
thing to implement at this stage in Rust's evolution.

## Async blocks vs async closures

As noted in the main text, `async` blocks and `async` closures are closely
related, and are roughly inter-expressible:

```rust
// equivalent
async { ... }
(async || { ... })()

// equivalent
async |..| { ... }
|..| async { ... }
Copy link
Contributor

@MajorBreakfast MajorBreakfast Apr 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be mentioned that the latter does not support return (stated later in the RFC https://github.com/withoutboats/rfcs/blob/async-await/text/0000-async_await.md#async-blocks). Async closures support return on the other hand.

```

We could consider having only one of the two constructs. However:

- There's a strong reason to have `async ||` for consistency with `async fn`;
such closures are often useful for higher-order constructs like constructing a
service.

- There's a strong reason to have `async` blocks: the initialization pattern
mentioned in the RFC text, and the fact that it provides a more
direct/primitive way of constructing futures.

The RFC proposes to include both constructs up front, since it seems inevitable
that we will want both of them, but we can always reconsider this question
before stabilization.

# Prior art
[prior-art]: #prior-art

Expand Down