Switched to pollster

pull/204/head
Joshua Barretto 3 years ago
parent 02994d1eb6
commit 12ba9bed0c

@ -18,4 +18,4 @@ cgmath = "0.18"
env_logger = "0.8"
log = "0.4"
wgpu = "0.9"
futures = "0.3"
pollster = "0.2"

@ -13,7 +13,7 @@ cgmath = "0.18"
env_logger = "0.8"
log = "0.4"
wgpu = "0.9"
futures = "0.3"
pollster = "0.2"
[[bin]]

@ -127,10 +127,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -116,10 +116,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state: State = block_on(State::new(&window));
let mut state: State = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -12,7 +12,7 @@ cgmath = "0.18"
env_logger = "0.8"
log = "0.4"
wgpu = "0.9"
futures = "0.3"
pollster = "0.2"
# NEW!
[build-dependencies]
@ -26,4 +26,4 @@ path = "src/main.rs"
[[bin]]
name = "tutorial3-challenge"
path = "src/challenge.rs"
path = "src/challenge.rs"

@ -238,10 +238,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -175,10 +175,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -12,7 +12,7 @@ winit = "0.25"
wgpu = "0.9"
env_logger = "0.8"
log = "0.4"
futures = "0.3"
pollster = "0.2"
# NEW!
bytemuck = { version = "1.4", features = [ "derive" ] }
@ -27,4 +27,4 @@ path = "src/main.rs"
[[bin]]
name = "tutorial4-challenge"
path = "src/challenge.rs"
path = "src/challenge.rs"

@ -317,10 +317,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -249,10 +249,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -12,7 +12,7 @@ bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
log = "0.4"
futures = "0.3"
pollster = "0.2"
image = "0.23"
wgpu = "0.9"
winit = "0.25"
@ -29,4 +29,4 @@ path = "src/main.rs"
[[bin]]
name = "tutorial5-challenge"
path = "src/challenge.rs"
path = "src/challenge.rs"

@ -347,10 +347,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -302,10 +302,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -10,7 +10,7 @@ bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
log = "0.4"
futures = "0.3"
pollster = "0.2"
image = "0.23"
wgpu = "0.9"
winit = "0.25"
@ -27,4 +27,4 @@ path = "src/main.rs"
[[bin]]
name = "tutorial6-challenge"
path = "src/challenge.rs"
path = "src/challenge.rs"

@ -529,10 +529,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -511,10 +511,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -10,7 +10,7 @@ bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
log = "0.4"
futures = "0.3"
pollster = "0.2"
image = "0.23"
wgpu = "0.9"
winit = "0.25"
@ -27,4 +27,4 @@ path = "src/main.rs"
[[bin]]
name = "tutorial7-challenge"
path = "src/challenge.rs"
path = "src/challenge.rs"

@ -662,10 +662,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -612,10 +612,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -9,7 +9,7 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
wgpu = "0.9"

@ -832,10 +832,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -638,10 +638,8 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
match event {

@ -9,7 +9,7 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
tobj = "3.0"
@ -28,4 +28,4 @@ path = "src/main.rs"
# [[bin]]
# name = "tutorial9-challenge"
# path = "src/challenge.rs"
# path = "src/challenge.rs"

@ -555,8 +555,9 @@ fn main() {
.build(&event_loop)
.unwrap();
use futures::executor::block_on;
let mut state = block_on(State::new(&window));
// Since main can't be async, we're going to need to block
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {

@ -9,7 +9,7 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
tobj = "3.0"
@ -23,4 +23,4 @@ glob = "0.3"
[[bin]]
name = "tutorial10-lighting"
path = "src/main.rs"
path = "src/main.rs"

@ -689,8 +689,7 @@ fn main() {
.with_title(title)
.build(&event_loop)
.unwrap();
use futures::executor::block_on;
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {

@ -9,7 +9,7 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
tobj = "3.0"

@ -742,8 +742,7 @@ fn main() {
.with_title(title)
.build(&event_loop)
.unwrap();
use futures::executor::block_on;
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {

@ -9,7 +9,7 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
tobj = "3.0"

@ -649,8 +649,7 @@ fn main() {
.with_title(title)
.build(&event_loop)
.unwrap();
use futures::executor::block_on;
let mut state = block_on(State::new(&window)); // NEW!
let mut state = pollster::block_on(State::new(&window)); // NEW!
let mut last_render_time = std::time::Instant::now();
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;

@ -9,7 +9,7 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
rayon = "1.4" # NEW!

@ -644,8 +644,7 @@ fn main() {
.with_title(title)
.build(&event_loop)
.unwrap();
use futures::executor::block_on;
let mut state = block_on(State::new(&window)); // NEW!
let mut state = pollster::block_on(State::new(&window)); // NEW!
let mut last_render_time = std::time::Instant::now();
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;

@ -9,7 +9,7 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = ["derive"]}
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
rayon = "1.4"

@ -585,8 +585,7 @@ fn main() {
.with_title(title)
.build(&event_loop)
.unwrap();
use futures::executor::block_on;
let mut state = block_on(State::new(&window)); // NEW!
let mut state = pollster::block_on(State::new(&window)); // NEW!
let mut last_render_time = std::time::Instant::now();
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;

@ -10,7 +10,7 @@ thiserror = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
tobj = "2.0"

@ -10,7 +10,7 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.8"
futures = "0.3"
pollster = "0.2"
image = "0.23"
log = "0.4"
tobj = "2.0"

@ -217,6 +217,5 @@ fn create_render_pipeline(
}
fn main() {
use futures::executor::block_on;
block_on(run());
pollster::block_on(run());
}

@ -9,7 +9,7 @@ edition = "2018"
[dependencies]
anyhow = "1.0"
wgpu = "0.9"
futures = "0.3"
pollster = "0.2"
imgui = "0.7"
imgui-wgpu = "0.15"
imgui-winit-support = "0.7"

@ -1,5 +1,4 @@
use anyhow::*;
use futures::executor::block_on;
use imgui::*;
use imgui_wgpu::{Renderer, RendererConfig};
use std::time::Duration;
@ -135,6 +134,6 @@ impl framework::Demo for ImguiDemo {
}
fn main() -> Result<()> {
block_on(framework::run::<ImguiDemo>())?;
pollster::block_on(framework::run::<ImguiDemo>())?;
Ok(())
}

@ -10,7 +10,7 @@ shaderc = "0.7"
anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
futures = "0.3"
pollster = "0.2"
wgpu = "0.9"
wgpu_glyph = "0.12"
rand = "0.8"

@ -8,7 +8,6 @@ mod util;
use input::Input;
use system::System;
use futures::executor::block_on;
use winit::event::*;
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::{Fullscreen, WindowBuilder};
@ -25,7 +24,7 @@ fn main() {
.unwrap();
window.set_cursor_visible(false);
let mut render = block_on(render::Render::new(&window, &video_mode));
let mut render = pollster::block_on(render::Render::new(&window, &video_mode));
let mut state = state::State {
ball: state::Ball {
position: (0.0, 0.0).into(),

@ -13,7 +13,7 @@ winit = "0.25"
shaderc = "0.7"
cgmath = "0.18"
wgpu = "0.9"
futures = "0.3.4"
pollster = "0.2"
[[bin]]
name = "windowless"

@ -193,6 +193,5 @@ async fn run() {
}
fn main() {
use futures::executor::block_on;
block_on(run());
pollster::block_on(run());
}

@ -14,7 +14,7 @@ cgmath = "0.18"
env_logger = "0.8"
log = "0.4"
wgpu = "0.9"
futures = "0.3"
pollster = "0.2"
```
## The code

@ -129,15 +129,13 @@ At the end of the method, we simply return the resulting struct.
We'll want to call this in our main method before we enter the event loop.
```rust
use futures::executor::block_on;
// Since main can't be async, we're going to need to block
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
```
<div class="note">
You can use libraries like [async_std](https://docs.rs/async_std) and [tokio](https://docs.rs/tokio) to make main async, so you can await futures. I've elected not to use these crates as this tutorial is not about writing an async application. We just need some way to interact with wgpu's async functions, and the [futures crate](https://docs.rs/futures) is enough for that.
You can use heavier libraries like [async_std](https://docs.rs/async_std) and [tokio](https://docs.rs/tokio) to make main async, so you can await futures. I've elected not to use these crates as this tutorial is not about writing an async application, and the futures created by wgpu do not require [special executor support](https://rust-lang.github.io/async-book/08_ecosystem/00_chapter.html#determining-ecosystem-compatibility). We just need some way to interact with wgpu's async functions, and the [pollster crate](https://docs.rs/pollster) is enough for that.
</div>

@ -428,7 +428,7 @@ cgmath = "0.18"
winit = "0.25"
env_logger = "0.8"
log = "0.4"
futures = "0.3"
pollster = "0.2"
wgpu ="0.6"
bytemuck = "1.4"
anyhow = "1.0" // NEW!

@ -418,12 +418,12 @@ self.light.position =
* old_position; // UPDATED!
```
We still need to calculate `dt`. Let's do that in the `main` function.
We still need to calculate `dt`. Let's do that in the `main` function.
```rust
fn main() {
// ...
let mut state = block_on(State::new(&window));
let mut state = pollster::block_on(State::new(&window));
let mut last_render_time = std::time::Instant::now();
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;

@ -57,7 +57,7 @@ let u32_size = std::mem::size_of::<u32>() as u32;
let output_buffer_size = (u32_size * texture_size * texture_size) as wgpu::BufferAddress;
let output_buffer_desc = wgpu::BufferDescriptor {
size: output_buffer_size,
usage: wgpu::BufferUsage::COPY_DST
usage: wgpu::BufferUsage::COPY_DST
// this tells wpgu that we want to read this buffer from the cpu
| wgpu::BufferUsage::MAP_READ,
label: None,
@ -265,7 +265,7 @@ output_buffer.unmap();
## Main is not asyncable
The `main()` method can't return a future, so we can't use the `async` keyword. We'll get around this by putting our code into a different function so that we can block on it in `main()`. You'll need to use a crate that can poll futures such as the [futures crate](https://docs.rs/futures).
The `main()` method can't return a future, so we can't use the `async` keyword. We'll get around this by putting our code into a different function so that we can block on it in `main()`. You'll need to use a crate that can poll futures such as the [pollster crate](https://docs.rs/pollster).
```rust
async fn run() {
@ -273,13 +273,12 @@ async fn run() {
}
fn main() {
use futures::executor::block_on;
block_on(run());
pollster::block_on(run());
}
```
With all that you should have an image like this.
With all that you should have an image like this.
![a brown triangle](./image-output.png)
<AutoGithubLink/>
<AutoGithubLink/>

Loading…
Cancel
Save