[][src]Crate thread_tryjoin

Ever needed to wait for a thread to finish, but thought you can still do work until it finishes?

JoinHandle#join() waits for the thread to finish and is blocking, so it doesn't allow you to try again and again.

Luckily there is a non-portable pthread API: pthread_tryjoin_np

This library provides convenient access through a try_join method on JoinHandle. It only works on Linux though. It uses JoinHandleExt to get to the underlying pthread_t handle.

Use an additional join to get to the actual underlying result of the thread.

Example

use thread_tryjoin::TryJoinHandle;

let t = thread::spawn(|| { thread::sleep(Duration::from_secs(1)); });
assert!(t.try_join().is_err());

To perform a join-with-timeout there is a try_timed_join method.

Example join-with-timeout

use thread_tryjoin::TryJoinHandle;

let t = thread::spawn(|| {
    thread::sleep(Duration::from_millis(200));
});
assert!(t.try_timed_join(Duration::from_millis(500)).is_ok());

Traits

TryJoinHandle

Try joining a thread.