Add is_finished to Task<T> (#6444)

# 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.

---
This commit is contained in:
BeastLe9enD 2022-11-02 12:27:22 +00:00
parent 5640ec855e
commit ed3ecda91d

View File

@ -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> {