Rename JoinHandle::is_running to is_finished and update docs.

Co-authored-by: Josh Triplett <josh@joshtriplett.org>
This commit is contained in:
Mara Bos 2022-03-03 11:19:50 +01:00
parent 2f8d1a835b
commit dadf2adbe9
2 changed files with 18 additions and 8 deletions

View File

@ -1443,13 +1443,18 @@ impl<T> JoinHandle<T> {
self.0.join()
}
/// Checks if the associated thread is still running its main function.
/// Checks if the associated thread has finished running its main function.
///
/// This might return `false` for a brief moment after the thread's main
/// This might return `true` for a brief moment after the thread's main
/// function has returned, but before the thread itself has stopped running.
/// However, once this returns `true`, [`join`][Self::join] can be expected
/// to return quickly, without blocking for any significant amount of time.
///
/// This function does not block. To block while waiting on the thread to finish,
/// use [`join`][Self::join].
#[unstable(feature = "thread_is_running", issue = "90470")]
pub fn is_running(&self) -> bool {
Arc::strong_count(&self.0.packet) > 1
pub fn is_finished(&self) -> bool {
Arc::strong_count(&self.0.packet) == 1
}
}

View File

@ -289,13 +289,18 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
self.0.join()
}
/// Checks if the associated thread is still running its main function.
/// Checks if the associated thread has finished running its main function.
///
/// This might return `false` for a brief moment after the thread's main
/// This might return `true` for a brief moment after the thread's main
/// function has returned, but before the thread itself has stopped running.
/// However, once this returns `true`, [`join`][Self::join] can be expected
/// to return quickly, without blocking for any significant amount of time.
///
/// This function does not block. To block while waiting on the thread to finish,
/// use [`join`][Self::join].
#[unstable(feature = "thread_is_running", issue = "90470")]
pub fn is_running(&self) -> bool {
Arc::strong_count(&self.0.packet) > 1
pub fn is_finished(&self) -> bool {
Arc::strong_count(&self.0.packet) == 1
}
}