-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpool.rs
32 lines (28 loc) · 857 Bytes
/
pool.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//! Task pool example - this demonstrates running several async tasks concurrently.
use async_std::task::sleep;
use bevy::{app::PanicHandlerPlugin, log::LogPlugin, prelude::*};
use bevy_async_task::{Duration, TaskPool};
use std::task::Poll;
fn system1(mut task_pool: TaskPool<'_, u64>) {
if task_pool.is_idle() {
info!("Queueing 5 tasks...");
for i in 1..=5 {
task_pool.spawn(async move {
sleep(Duration::from_millis(i * 1000)).await;
i
});
}
}
for status in task_pool.iter_poll() {
if let Poll::Ready(t) = status {
info!("Received {t}");
}
}
}
/// Entry point
pub fn main() {
App::new()
.add_plugins((MinimalPlugins, LogPlugin::default(), PanicHandlerPlugin))
.add_systems(Update, system1)
.run();
}