-
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
3 changed files
with
16 additions
and
15 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
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,31 +1,22 @@ | ||
use async_std::task::sleep; | ||
use bevy::{app::PanicHandlerPlugin, log::LogPlugin, prelude::*}; | ||
use bevy_async_task::{AsyncTask, AsyncTaskRunner}; | ||
use std::time::Duration; | ||
|
||
/// You can block with a task runner | ||
fn system1(mut task_executor: AsyncTaskRunner<u32>) { | ||
let result = task_executor.blocking_recv(async { | ||
sleep(Duration::from_millis(1000)).await; | ||
1 | ||
}); | ||
let result = task_executor.blocking_recv(async { 1 }); | ||
info!("Received {result}"); | ||
} | ||
|
||
/// Or block on a task, without the need of a system parameter. | ||
fn system2() { | ||
let result = AsyncTask::new(async { | ||
sleep(Duration::from_millis(1000)).await; | ||
2 | ||
}) | ||
.blocking_recv(); | ||
let result = AsyncTask::new(async { 2 }).blocking_recv(); | ||
info!("Received {result}"); | ||
} | ||
|
||
pub fn main() { | ||
App::new() | ||
.add_plugins((MinimalPlugins, LogPlugin::default(), PanicHandlerPlugin)) | ||
.add_systems(Update, system1) | ||
.add_systems(Update, system2) | ||
.add_systems(Startup, system2) | ||
.add_systems(Startup, system1) | ||
.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