join
fn join<T>(Thread t) -> Result<T, ThreadError> Import
Source: use thread::{join}; 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#
| Name | Type |
|---|---|
t | Thread |
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::scopespawn: Runsf(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 ofvalueon the channel.recv: Takes the next value from the channel, waiting until one arrives.try_send: Sendsvaluewithout waiting.try_recv: Takes the next value if there is one, without waiting.