Skip to content

Commit

Permalink
update original
Browse files Browse the repository at this point in the history
  • Loading branch information
funkill committed Oct 6, 2024
1 parent a17fbee commit bc73a95
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions async-book/examples/02_02_future_trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ where
// the second!
Poll::Ready(()) => self.first.take(),
// We couldn't yet complete the first future.
// Notice that we disrupt the flow of the `pool` function with the `return` statement.
Poll::Pending => return Poll::Pending,
};
}
Expand Down
4 changes: 2 additions & 2 deletions async-book/examples/02_04_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Spawner {
future: Mutex::new(Some(future)),
task_sender: self.task_sender.clone(),
});
self.task_sender.send(task).expect("too many tasks queued");
self.task_sender.try_send(task).expect("too many tasks queued");
}
}
// ANCHOR_END: spawn_fn
Expand All @@ -74,7 +74,7 @@ impl ArcWake for Task {
let cloned = arc_self.clone();
arc_self
.task_sender
.send(cloned)
.try_send(cloned)
.expect("too many tasks queued");
}
}
Expand Down
2 changes: 1 addition & 1 deletion async-book/examples/09_05_final_tcp_server/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello!</title>
<title>Oops!</title>
</head>
<body>
<h1>Oops!</h1>
Expand Down
4 changes: 2 additions & 2 deletions async-book/src/01_getting_started/03_state_of_async_rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ language features and library support:
details.

Some language features you may be used to from synchronous Rust are not yet
available in async Rust. Notably, Rust does not let you declare async
functions in traits. Instead, you need to use workarounds to achieve the same
available in async Rust. Notably, Rust did not let you declare async
functions in traits until 1.75.0 stable (and still has limitations on dynamic dispatch for those traits). Instead, you need to use workarounds to achieve the same
result, which can be more verbose.

## Compiling and debugging
Expand Down
2 changes: 1 addition & 1 deletion async-book/src/02_execution/05_io.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ event occurs. In the case of our `SocketRead` example above, the
impl Socket {
fn set_readable_callback(&self, waker: Waker) {
// `local_executor` is a reference to the local executor.
// this could be provided at creation of the socket, but in practice
// This could be provided at creation of the socket, but in practice
// many executor implementations pass it down through thread local
// storage for convenience.
let local_executor = self.local_executor;
Expand Down
6 changes: 4 additions & 2 deletions async-book/src/04_pinning/01_chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ it safe to create references to values inside an `async` block.

## Pinning in Detail

Let's try to understand pinning by using an slightly simpler example. The problem we encounter
Let's try to understand pinning by using a slightly simpler example. The problem we encounter
above is a problem that ultimately boils down to how we handle references in self-referential
types in Rust.

Expand Down Expand Up @@ -139,7 +139,7 @@ impl Test {
```

`Test` provides methods to get a reference to the value of the fields `a` and `b`. Since `b` is a
reference to `a` we store it as a pointer since the borrowing rules of Rust doesn't allow us to
reference to `a` we store it as a pointer since the borrowing rules of Rust don't allow us to
define this lifetime. We now have what we call a self-referential struct.

Our example works fine if we don't move any of our data around as you can observe by running
Expand Down Expand Up @@ -553,10 +553,12 @@ note: required by a bound in `std::pin::Pin::<&'a mut T>::get_mut`
> # this.b = self_ptr;
> # }
> #
> # #[allow(unused)]
> # fn a<'a>(self: Pin<&'a Self>) -> &'a str {
> # &self.get_ref().a
> # }
> #
> # #[allow(unused)]
> # fn b<'a>(self: Pin<&'a Self>) -> &'a String {
> # assert!(!self.b.is_null(), "Test::b called without Test::init being called first");
> # unsafe { &*(self.b) }
Expand Down
2 changes: 1 addition & 1 deletion async-book/src/06_multiple_futures/02_join.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The `futures::join` macro makes it possible to wait for multiple different
futures to complete while executing them all concurrently.

# `join!`
## `join!`

When performing multiple asynchronous operations, it's tempting to simply
`.await` them in a series:
Expand Down
2 changes: 2 additions & 0 deletions async-book/src/07_workarounds/05_async_in_traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ per-function-call. This is not a significant cost for the vast majority
of applications, but should be considered when deciding whether to use
this functionality in the public API of a low-level function that is expected
to be called millions of times a second.

Last updates: https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ As long as `handle_connection` does not block, a slow request will no longer pre
{{#include ../../examples/09_04_concurrent_tcp_server/src/main.rs:main_func}}
```
# Serving Requests in Parallel
Our example so far has largely presented concurrency (using async code)
as an alternative to parallelism (using threads).
Our example so far has largely presented cooperative multitasking concurrency (using async code)
as an alternative to preemptive multitasking (using threads).
However, async code and threads are not mutually exclusive.
In our example, `for_each_concurrent` processes each connection concurrently, but on the same thread.
The `async-std` crate allows us to spawn tasks onto separate threads as well.
Expand All @@ -49,6 +49,6 @@ Here's what that would look like:
```rust
{{#include ../../examples/09_05_final_tcp_server/src/main.rs:main_func}}
```
Now we are using both concurrency and parallelism to handle multiple requests at the same time!
Now we are using both cooperative multitasking concurrency and preemptive multitasking to handle multiple requests at the same time!
See the [section on multithreaded executors](../08_ecosystem/00_chapter.md#single-threading-vs-multithreading)
for more information.
for more information.

0 comments on commit bc73a95

Please sign in to comment.