2025-04-03 21:25:31 -04:00

21 lines
565 B
Rust

use bevy::{
prelude::*,
tasks::{block_on, futures_lite::future},
};
use crate::resources::DirworldTasks;
pub fn remove_completed_tasks(mut commands: Commands, mut tasks: ResMut<DirworldTasks>) {
tasks.retain(|_, task| match task {
Some(task) => {
if task.is_finished() {
if let Some(Some(mut command_queue)) = block_on(future::poll_once(&mut *task)) {
commands.append(&mut command_queue);
}
}
!task.is_finished()
}
None => true,
});
}