passing tests on latest nightly
This commit is contained in:
@@ -203,7 +203,7 @@ executor.</p>
|
|||||||
<p>The bulk of an async program will consist of non-leaf-futures, which are a kind
|
<p>The bulk of an async program will consist of non-leaf-futures, which are a kind
|
||||||
of pause-able computation. This is an important distinction since these futures represents a <em>set of operations</em>. Often, such a task will <code>await</code> a leaf future
|
of pause-able computation. This is an important distinction since these futures represents a <em>set of operations</em>. Often, such a task will <code>await</code> a leaf future
|
||||||
as one of many operations to complete the task.</p>
|
as one of many operations to complete the task.</p>
|
||||||
<pre><code class="language-rust ignore noplaypen">// Non-leaf-future
|
<pre><code class="language-rust ignore noplaypen edition2018">// Non-leaf-future
|
||||||
let non_leaf = async {
|
let non_leaf = async {
|
||||||
let mut stream = TcpStream::connect("127.0.0.1:3000").await.unwrap();// <- yield
|
let mut stream = TcpStream::connect("127.0.0.1:3000").await.unwrap();// <- yield
|
||||||
println!("connected!");
|
println!("connected!");
|
||||||
@@ -312,21 +312,6 @@ it needs to be, so go on and read these chapters if you feel a bit unsure. </p>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -348,21 +348,6 @@ use purely global functions and state, or any other way you wish.</p>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -699,21 +699,6 @@ pub fn main() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -470,21 +470,6 @@ we're soon finished.</p>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -1043,21 +1043,6 @@ exploration will get a lot easier. </p>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -392,21 +392,6 @@ impl Drop for Reactor {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -254,21 +254,6 @@ articles I've already linked to in the book, here are some of my suggestions:</p
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -212,21 +212,6 @@ very well written and very helpful. So thanks!</p>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -220,21 +220,6 @@ very well written and very helpful. So thanks!</p>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ executor.</p>
|
|||||||
<p>The bulk of an async program will consist of non-leaf-futures, which are a kind
|
<p>The bulk of an async program will consist of non-leaf-futures, which are a kind
|
||||||
of pause-able computation. This is an important distinction since these futures represents a <em>set of operations</em>. Often, such a task will <code>await</code> a leaf future
|
of pause-able computation. This is an important distinction since these futures represents a <em>set of operations</em>. Often, such a task will <code>await</code> a leaf future
|
||||||
as one of many operations to complete the task.</p>
|
as one of many operations to complete the task.</p>
|
||||||
<pre><code class="language-rust ignore noplaypen">// Non-leaf-future
|
<pre><code class="language-rust ignore noplaypen edition2018">// Non-leaf-future
|
||||||
let non_leaf = async {
|
let non_leaf = async {
|
||||||
let mut stream = TcpStream::connect("127.0.0.1:3000").await.unwrap();// <- yield
|
let mut stream = TcpStream::connect("127.0.0.1:3000").await.unwrap();// <- yield
|
||||||
println!("connected!");
|
println!("connected!");
|
||||||
@@ -2424,21 +2424,6 @@ articles I've already linked to in the book, here are some of my suggestions:</p
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Livereload script (if served using the cli tool) -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var socket = new WebSocket("ws://localhost:3001");
|
|
||||||
socket.onmessage = function (event) {
|
|
||||||
if (event.data === "reload") {
|
|
||||||
socket.close();
|
|
||||||
location.reload(true); // force reload from server (not from cache)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Google Analytics Tag -->
|
<!-- Google Analytics Tag -->
|
||||||
|
|||||||
@@ -518,6 +518,12 @@ Thanks to [PR#45337][pr45337] you can actually run code like the one in our
|
|||||||
example in Rust today using the `static` keyword on nightly. Try it for
|
example in Rust today using the `static` keyword on nightly. Try it for
|
||||||
yourself:
|
yourself:
|
||||||
|
|
||||||
|
Beware that the API is changing rapidly. As I was writing this book
|
||||||
|
Generators had an API change adding support for a "resume" argument to
|
||||||
|
be passed into the generator closure.
|
||||||
|
|
||||||
|
Follow the progress on the [tracking issue #43122][issue43122] for [RFC#2033][rfc2033].
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#![feature(generators, generator_trait)]
|
#![feature(generators, generator_trait)]
|
||||||
use std::ops::{Generator, GeneratorState};
|
use std::ops::{Generator, GeneratorState};
|
||||||
@@ -541,16 +547,16 @@ pub fn main() {
|
|||||||
let mut pinned1 = Box::pin(gen1);
|
let mut pinned1 = Box::pin(gen1);
|
||||||
let mut pinned2 = Box::pin(gen2);
|
let mut pinned2 = Box::pin(gen2);
|
||||||
|
|
||||||
if let GeneratorState::Yielded(n) = pinned1.as_mut().resume() {
|
if let GeneratorState::Yielded(n) = pinned1.as_mut().resume(()) {
|
||||||
println!("Gen1 got value {}", n);
|
println!("Gen1 got value {}", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let GeneratorState::Yielded(n) = pinned2.as_mut().resume() {
|
if let GeneratorState::Yielded(n) = pinned2.as_mut().resume(()) {
|
||||||
println!("Gen2 got value {}", n);
|
println!("Gen2 got value {}", n);
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = pinned1.as_mut().resume();
|
let _ = pinned1.as_mut().resume(());
|
||||||
let _ = pinned2.as_mut().resume();
|
let _ = pinned2.as_mut().resume(());
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -559,4 +565,5 @@ pub fn main() {
|
|||||||
[rfc1823]: https://github.com/rust-lang/rfcs/pull/1823
|
[rfc1823]: https://github.com/rust-lang/rfcs/pull/1823
|
||||||
[rfc1832]: https://github.com/rust-lang/rfcs/pull/1832
|
[rfc1832]: https://github.com/rust-lang/rfcs/pull/1832
|
||||||
[optimizing-await]: https://tmandry.gitlab.io/blog/posts/optimizing-await-1/
|
[optimizing-await]: https://tmandry.gitlab.io/blog/posts/optimizing-await-1/
|
||||||
[pr45337]: https://github.com/rust-lang/rust/pull/45337/files
|
[pr45337]: https://github.com/rust-lang/rust/pull/45337/files
|
||||||
|
[issue43122]: https://github.com/rust-lang/rust/issues/43122
|
||||||
Reference in New Issue
Block a user