Skip to content

Commit 67d2a17

Browse files
Added a way to obtain an indication of the current task state (#19)
1 parent e6daa4f commit 67d2a17

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/task.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ impl<T> Task<T> {
395395
let header = ptr as *const Header;
396396
unsafe { &*header }
397397
}
398+
399+
/// Returns `true` if the current task is finished.
400+
///
401+
/// Note that in a multithreaded environment, this task can change finish immediately after calling this function.
402+
pub fn is_finished(&self) -> bool {
403+
let ptr = self.ptr.as_ptr();
404+
let header = ptr as *const Header;
405+
406+
unsafe {
407+
let state = (*header).state.load(Ordering::Acquire);
408+
state & (CLOSED | COMPLETED) != 0
409+
}
410+
}
398411
}
399412

400413
impl<T> Drop for Task<T> {

0 commit comments

Comments
 (0)