Skip to content

Commit

Permalink
Add JoinHandle missing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 24, 2016
1 parent 1b38776 commit 00645e8
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions src/libstd/thread/mod.rs
Expand Up @@ -749,7 +749,7 @@ impl<T> JoinInner<T> {
///
/// A `JoinHandle` *detaches* the child thread when it is dropped.
///
/// Due to platform restrictions, it is not possible to `Clone` this
/// Due to platform restrictions, it is not possible to [`Clone`] this
/// handle: the ability to join a child thread is a uniquely-owned
/// permission.
///
Expand All @@ -760,7 +760,7 @@ impl<T> JoinInner<T> {
///
/// Creation from [`thread::spawn`]:
///
/// ```rust
/// ```
/// use std::thread;
///
/// let join_handle: thread::JoinHandle<_> = thread::spawn(|| {
Expand All @@ -770,7 +770,7 @@ impl<T> JoinInner<T> {
///
/// Creation from [`thread::Builder::spawn`]:
///
/// ```rust
/// ```
/// use std::thread;
///
/// let builder = thread::Builder::new();
Expand All @@ -780,22 +780,56 @@ impl<T> JoinInner<T> {
/// }).unwrap();
/// ```
///
/// [`Clone`]: ../../std/clone/trait.Clone.html
/// [`thread::spawn`]: fn.spawn.html
/// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn
#[stable(feature = "rust1", since = "1.0.0")]
pub struct JoinHandle<T>(JoinInner<T>);

impl<T> JoinHandle<T> {
/// Extracts a handle to the underlying thread
/// Extracts a handle to the underlying thread.
///
/// # Examples
///
/// ```
/// #![feature(thread_id)]
///
/// use std::thread;
///
/// let builder = thread::Builder::new();
///
/// let join_handle: thread::JoinHandle<_> = builder.spawn(|| {
/// // some work here
/// }).unwrap();
///
/// let thread = join_handle.thread();
/// println!("thread id: {:?}", thread.id());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn thread(&self) -> &Thread {
&self.0.thread
}

/// Waits for the associated thread to finish.
///
/// If the child thread panics, `Err` is returned with the parameter given
/// to `panic`.
/// If the child thread panics, [`Err`] is returned with the parameter given
/// to [`panic`].
///
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
/// [`panic!`]: ../../std/macro.panic.html
///
/// # Examples
///
/// ```
/// use std::thread;
///
/// let builder = thread::Builder::new();
///
/// let join_handle: thread::JoinHandle<_> = builder.spawn(|| {
/// // some work here
/// }).unwrap();
/// join_handle.join().expect("Couldn't join on the associated thread");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn join(mut self) -> Result<T> {
self.0.join()
Expand Down

0 comments on commit 00645e8

Please sign in to comment.