Skip to content

Commit

Permalink
improve error message when sending the result fails
Browse files Browse the repository at this point in the history
  • Loading branch information
pubrrr committed Jun 12, 2022
1 parent 550a0f1 commit 8163fde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 10 additions & 7 deletions crates/bevy_tasks/src/task_pool.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use async_channel::bounded;
use std::{
any::type_name,
future::Future,
mem,
pin::Pin,
sync::Arc,
thread::{self, JoinHandle},
};

use bevy_utils::tracing::warn;
use bevy_utils::tracing::error;
use futures_lite::{future, pin};

use crate::{PollableTask, Task};
Expand Down Expand Up @@ -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<T>(
&self,
future: impl Future<Output = T> + Send + 'static,
) -> PollableTask<T>
pub fn spawn_pollable<F, T>(&self, future: F) -> PollableTask<T>
where
F: Future<Output = T> + 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<Output={return_name}>`) failed, because the receiving `PollableTask` was dropped",
future_name=type_name::<F>(),
return_name=type_name::<T>(),
),
}
});
PollableTask::new(receiver, task)
Expand Down

0 comments on commit 8163fde

Please sign in to comment.