Function in thread compiler

detach

fn detach(Thread t) -> Result<unit, ThreadError>
Import
use thread::{detach};
Source: 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#

NameType
tThread

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::join
  • spawn: Runs f(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 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.
  • close: Closes the channel: no more sends.
↑ ↓ navigate ↵ open