detach
fn detach(Thread t) -> Result<unit, ThreadError> Import
Source: use thread::{detach}; compiler/src/builtin_docs/thread.hy Lets the thread run to completion without being joined.
Its result is dropped, and the program does not wait for it when main
returns. A later join on the handle is Err(ThreadError::JoinFailed),
as is detaching a thread that was already joined.
Parameters#
| Name | Type |
|---|---|
t | Thread |
Returns#
Result<unit, ThreadError>
Examples#
use thread::{spawn, detach, join, ThreadError};
use tests::assert;
fn work() -> int {
return 1;
}
fn main() {
let t = match spawn(work) {
Result::Ok(t) => t,
Result::Err(_) => panic "spawn failed",
};
assert!(match detach(t) { Result::Ok(_) => true, Result::Err(_) => false });
let joined = match join(t) {
Result::Err(ThreadError::JoinFailed) => true,
default => false,
};
assert!(joined);
}
See also#
thread::joinspawn: Runsf(arg)on another OS thread and returns a handle to it.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.close: Closes the channel: no more sends.