Function in thread compiler

join

fn join<T>(Thread t) -> Result<T, ThreadError>
Import
use thread::{join};
Source: compiler/src/builtin_docs/thread.hy

Waits for the thread to finish and returns the value its function returned.

Returns Err(ThreadError::JoinFailed) if the thread was already joined or detached, or if its function panicked (the panic message is printed to stderr). Inside a task::scope, only the joining task waits; other tasks keep running.

Parameters#

NameType
tThread

Returns#

Result<T, ThreadError>

Examples#

use thread::{spawn, join, ThreadError};
use tests::assert;
fn answer() -> int {
    return 42;
}

fn main() {
    let t = match spawn(answer) {
        Result::Ok(t) => t,
        Result::Err(_) => panic "spawn failed",
    };
    assert!(match join(t) { Result::Ok(n) => n == 42, Result::Err(_) => false });
    let again = match join(t) {
        Result::Err(ThreadError::JoinFailed) => true,
        default => false,
    };
    assert!(again);
}

See also#

  • task::scope
  • spawn: Runs f(arg) on another OS thread and returns a handle to it.
  • detach: Lets the thread run to completion without being joined.
  • channel: Creates an unbounded channel and returns its (Sender, Receiver) ends.
  • send: Sends a copy of value on the channel.
  • recv: Takes the next value from the channel, waiting until one arrives.
  • try_send: Sends value without waiting.
  • try_recv: Takes the next value if there is one, without waiting.
↑ ↓ navigate ↵ open