From 8163fdec347b24b730c383dee1a143cd276cd526 Mon Sep 17 00:00:00 2001 From: pubrrr Date: Sun, 12 Jun 2022 13:24:52 +0200 Subject: [PATCH] improve error message when sending the result fails --- crates/bevy_tasks/Cargo.toml | 2 +- crates/bevy_tasks/src/task_pool.rs | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/bevy_tasks/Cargo.toml b/crates/bevy_tasks/Cargo.toml index 72ca31b17950b..98cae6d4d4b3a 100644 --- a/crates/bevy_tasks/Cargo.toml +++ b/crates/bevy_tasks/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [dependencies] -bevy_utils = { path = "../bevy_utils", version = "0.6.0" } +bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } futures-lite = "1.4.0" event-listener = "2.5.2" diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index 0956117248476..99bc4631767ea 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -1,5 +1,6 @@ use async_channel::bounded; use std::{ + any::type_name, future::Future, mem, pin::Pin, @@ -7,7 +8,7 @@ use std::{ thread::{self, JoinHandle}, }; -use bevy_utils::tracing::warn; +use bevy_utils::tracing::error; use futures_lite::{future, pin}; use crate::{PollableTask, Task}; @@ -232,19 +233,21 @@ impl TaskPool { /// Spawns a static future onto the thread pool. The returned `PollableTask` is not a future, /// but can be polled in system functions on every frame update without being blocked on - pub fn spawn_pollable( - &self, - future: impl Future + Send + 'static, - ) -> PollableTask + pub fn spawn_pollable(&self, future: F) -> PollableTask where + F: Future + Send + 'static, T: Send + Sync + 'static, { let (sender, receiver) = bounded(1); let task = self.spawn(async move { let result = future.await; match sender.send(result).await { - Ok(_) => {} - Err(_) => warn!("Could not send result of task to receiver"), + Ok(()) => {} + Err(_) => error!( + "Sending result for future {future_name} (`Future`) failed, because the receiving `PollableTask` was dropped", + future_name=type_name::(), + return_name=type_name::(), + ), } }); PollableTask::new(receiver, task)