making tests pass on windows

This commit is contained in:
Carl Fredrik Samson
2020-04-05 01:01:56 +02:00
parent 971288868b
commit 5ec0336d66
7 changed files with 29 additions and 26 deletions

View File

@@ -272,7 +272,7 @@ in that book. The code below is wildly unsafe and it's just to show a real examp
It's not in any way meant to showcase "best practice". Just so we're on It's not in any way meant to showcase "best practice". Just so we're on
the same page.</p> the same page.</p>
</blockquote> </blockquote>
<pre><pre class="playpen"><code class="language-rust">#![feature(asm)] <pre><pre class="playpen"><code class="language-rust edition2018">#![feature(asm)]
#![feature(naked_functions)] #![feature(naked_functions)]
use std::ptr; use std::ptr;
@@ -464,7 +464,7 @@ unsafe fn switch(old: *mut ThreadContext, new: *const ThreadContext) {
: &quot;alignstack&quot; : &quot;alignstack&quot;
); );
} }
# #[cfg(not(windows))]
fn main() { fn main() {
let mut runtime = Runtime::new(); let mut runtime = Runtime::new();
runtime.init(); runtime.init();
@@ -481,7 +481,8 @@ fn main() {
}); });
runtime.run(); runtime.run();
} }
# #[cfg(windows)]
# fn main() { }
</code></pre></pre> </code></pre></pre>
<p>Still hanging in there? Good. Don't get frustrated if the code above is <p>Still hanging in there? Good. Don't get frustrated if the code above is
difficult to understand. If I hadn't written it myself I would probably feel difficult to understand. If I hadn't written it myself I would probably feel
@@ -627,7 +628,7 @@ a state machine which can be in one of three states: <code>pending</code>, <code
promise in the state <code>pending</code>.</p> promise in the state <code>pending</code>.</p>
<p>Since promises are re-written as state machines they also enable an even better <p>Since promises are re-written as state machines they also enable an even better
syntax where we now can write our last example like this:</p> syntax where we now can write our last example like this:</p>
<pre><code>async function run() { <pre><code class="language-js ignore">async function run() {
await timer(200); await timer(200);
await timer(100); await timer(100);
await timer(50); await timer(50);

View File

@@ -648,16 +648,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!(&quot;Gen1 got value {}&quot;, n); println!(&quot;Gen1 got value {}&quot;, n);
} }
if let GeneratorState::Yielded(n) = pinned2.as_mut().resume() { if let GeneratorState::Yielded(n) = pinned2.as_mut().resume(()) {
println!(&quot;Gen2 got value {}&quot;, n); println!(&quot;Gen2 got value {}&quot;, n);
}; };
let _ = pinned1.as_mut().resume(); let _ = pinned1.as_mut().resume(());
let _ = pinned2.as_mut().resume(); let _ = pinned2.as_mut().resume(());
} }
</code></pre></pre> </code></pre></pre>

View File

@@ -314,7 +314,7 @@ in that book. The code below is wildly unsafe and it's just to show a real examp
It's not in any way meant to showcase &quot;best practice&quot;. Just so we're on It's not in any way meant to showcase &quot;best practice&quot;. Just so we're on
the same page.</p> the same page.</p>
</blockquote> </blockquote>
<pre><pre class="playpen"><code class="language-rust">#![feature(asm)] <pre><pre class="playpen"><code class="language-rust edition2018">#![feature(asm)]
#![feature(naked_functions)] #![feature(naked_functions)]
use std::ptr; use std::ptr;
@@ -506,7 +506,7 @@ unsafe fn switch(old: *mut ThreadContext, new: *const ThreadContext) {
: &quot;alignstack&quot; : &quot;alignstack&quot;
); );
} }
# #[cfg(not(windows))]
fn main() { fn main() {
let mut runtime = Runtime::new(); let mut runtime = Runtime::new();
runtime.init(); runtime.init();
@@ -523,7 +523,8 @@ fn main() {
}); });
runtime.run(); runtime.run();
} }
# #[cfg(windows)]
# fn main() { }
</code></pre></pre> </code></pre></pre>
<p>Still hanging in there? Good. Don't get frustrated if the code above is <p>Still hanging in there? Good. Don't get frustrated if the code above is
difficult to understand. If I hadn't written it myself I would probably feel difficult to understand. If I hadn't written it myself I would probably feel
@@ -669,7 +670,7 @@ a state machine which can be in one of three states: <code>pending</code>, <code
promise in the state <code>pending</code>.</p> promise in the state <code>pending</code>.</p>
<p>Since promises are re-written as state machines they also enable an even better <p>Since promises are re-written as state machines they also enable an even better
syntax where we now can write our last example like this:</p> syntax where we now can write our last example like this:</p>
<pre><code>async function run() { <pre><code class="language-js ignore">async function run() {
await timer(200); await timer(200);
await timer(100); await timer(100);
await timer(50); await timer(50);
@@ -1474,16 +1475,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!(&quot;Gen1 got value {}&quot;, n); println!(&quot;Gen1 got value {}&quot;, n);
} }
if let GeneratorState::Yielded(n) = pinned2.as_mut().resume() { if let GeneratorState::Yielded(n) = pinned2.as_mut().resume(()) {
println!(&quot;Gen2 got value {}&quot;, n); println!(&quot;Gen2 got value {}&quot;, n);
}; };
let _ = pinned1.as_mut().resume(); let _ = pinned1.as_mut().resume(());
let _ = pinned2.as_mut().resume(); let _ = pinned2.as_mut().resume(());
} }
</code></pre></pre> </code></pre></pre>
<h1><a class="header" href="#pin" id="pin">Pin</a></h1> <h1><a class="header" href="#pin" id="pin">Pin</a></h1>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -138,7 +138,7 @@ this:
> It's not in any way meant to showcase "best practice". Just so we're on > It's not in any way meant to showcase "best practice". Just so we're on
> the same page. > the same page.
```rust ```rust, edition2018
#![feature(asm)] #![feature(asm)]
#![feature(naked_functions)] #![feature(naked_functions)]
use std::ptr; use std::ptr;
@@ -331,7 +331,7 @@ unsafe fn switch(old: *mut ThreadContext, new: *const ThreadContext) {
: "alignstack" : "alignstack"
); );
} }
# #[cfg(not(windows))]
fn main() { fn main() {
let mut runtime = Runtime::new(); let mut runtime = Runtime::new();
runtime.init(); runtime.init();
@@ -348,7 +348,8 @@ fn main() {
}); });
runtime.run(); runtime.run();
} }
# #[cfg(windows)]
# fn main() { }
``` ```
Still hanging in there? Good. Don't get frustrated if the code above is Still hanging in there? Good. Don't get frustrated if the code above is
@@ -516,7 +517,7 @@ promise in the state `pending`.
Since promises are re-written as state machines they also enable an even better Since promises are re-written as state machines they also enable an even better
syntax where we now can write our last example like this: syntax where we now can write our last example like this:
``` ```js, ignore
async function run() { async function run() {
await timer(200); await timer(200);
await timer(100); await timer(100);

View File

@@ -541,16 +541,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(());
} }
``` ```