-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
400 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# LINEBENDER LINT SET - .clippy.toml - v1 | ||
# See https://linebender.org/wiki/canonical-lints/ | ||
# The default Clippy value is capped at 8 bytes, which was chosen to improve performance on 32-bit. | ||
# Given that we are building for the future and even low-end mobile phones have 64-bit CPUs, | ||
# it makes sense to optimize for 64-bit and accept the performance hits on 32-bit. | ||
# 16 bytes is the number of bytes that fits into two 64-bit CPU registers. | ||
trivial-copy-size-limit = 16 | ||
# END LINEBENDER LINT SET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Cross system example - This example shows how to start a task from one system and poll it from | ||
//! another through a resource. | ||
use async_std::task::sleep; | ||
use bevy::{app::PanicHandlerPlugin, log::LogPlugin, prelude::*, tasks::AsyncComputeTaskPool}; | ||
use bevy_async_task::{AsyncReceiver, AsyncTask}; | ||
use std::time::Duration; | ||
|
||
#[derive(Resource, DerefMut, Deref, Default)] | ||
struct MyTask(Option<AsyncReceiver<u32>>); | ||
|
||
/// An async task that takes time to compute! | ||
async fn long_task() -> u32 { | ||
sleep(Duration::from_millis(1000)).await; | ||
5 | ||
} | ||
|
||
fn system1_start(mut my_task: ResMut<'_, MyTask>) { | ||
let (fut, receiver) = AsyncTask::new(long_task()).into_parts(); | ||
my_task.replace(receiver); | ||
AsyncComputeTaskPool::get().spawn_local(fut).detach(); | ||
info!("Started!"); | ||
} | ||
|
||
fn system2_poll(mut my_task: ResMut<'_, MyTask>) { | ||
let Some(receiver) = my_task.0.as_mut() else { | ||
return; | ||
}; | ||
match receiver.try_recv() { | ||
Some(v) => { | ||
info!("Received {v}"); | ||
} | ||
None => { | ||
// Waiting... | ||
} | ||
} | ||
} | ||
|
||
/// Entry point | ||
pub fn main() { | ||
App::new() | ||
.init_resource::<MyTask>() | ||
.add_plugins((MinimalPlugins, LogPlugin::default(), PanicHandlerPlugin)) | ||
.add_systems(Startup, system1_start) | ||
.add_systems(Update, system2_poll) | ||
.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[package] | ||
name = "run_wasm" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.