Skip to content

Commit

Permalink
Add is_finished to Task<T> (bevyengine#6444)
Browse files Browse the repository at this point in the history
# Objective

In some scenarios it can be useful to check if a task has been finished without polling it. I added a function called `is_finished` to check if a task has been finished.

## Solution

Since `async_task` supports it out of the box, it is just a simple wrapper function.

---
  • Loading branch information
BeastLe9enD authored and ItsDoot committed Feb 1, 2023
1 parent 3d60373 commit a1684a6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/bevy_tasks/src/task.rs
Expand Up @@ -41,6 +41,15 @@ impl<T> Task<T> {
pub async fn cancel(self) -> Option<T> {
self.0.cancel().await
}

/// Returns `true` if the current task is finished.
///
///
/// Unlike poll, it doesn't resolve the final value, it just checks if the task has finished.
/// Note that in a multithreaded environment, this task can be finished immediately after calling this function.
pub fn is_finished(&self) -> bool {
self.0.is_finished()
}
}

impl<T> Future for Task<T> {
Expand Down

0 comments on commit a1684a6

Please sign in to comment.