Skip to content

Remove task in handle_tasks in async_compute example #20175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions examples/async_tasks/async_compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ fn spawn_tasks(mut commands: Commands) {
Mesh3d(box_mesh_handle),
MeshMaterial3d(box_material_handle),
transform,
))
// Task is complete, so remove task component from entity
.remove::<ComputeTransform>();
));
});

command_queue
Expand All @@ -108,11 +106,16 @@ fn spawn_tasks(mut commands: Commands) {
/// tasks to see if they're complete. If the task is complete it takes the result, adds a
/// new [`Mesh3d`] and [`MeshMaterial3d`] to the entity using the result from the task's work, and
/// removes the task component from the entity.
fn handle_tasks(mut commands: Commands, mut transform_tasks: Query<&mut ComputeTransform>) {
for mut task in &mut transform_tasks {
fn handle_tasks(
mut commands: Commands,
mut transform_tasks: Query<(Entity, &mut ComputeTransform)>,
) {
for (entity, mut task) in &mut transform_tasks {
if let Some(mut commands_queue) = block_on(future::poll_once(&mut task.0)) {
// append the returned command queue to have it execute later
commands.append(&mut commands_queue);
// Task is complete, so remove task component from entity
commands.entity(entity).remove::<ComputeTransform>();
}
}
}
Expand Down
Loading