-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpool.rs
More file actions
36 lines (31 loc) · 890 Bytes
/
pool.rs
File metadata and controls
36 lines (31 loc) · 890 Bytes
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
33
34
35
36
//! Task pool example - this demonstrates running several async tasks concurrently.
use core::time::Duration;
use std::task::Poll;
use bevy::app::PanicHandlerPlugin;
use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy_async_task::TaskPool;
use bevy_async_task::sleep;
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();
}