Function in thread compiler

send

fn send<T>(Sender tx, T value) -> Result<unit, ThreadError>
Import
use thread::{send};
Source: compiler/src/builtin_docs/thread.hy

Sends a copy of value on the channel.

Never waits, since channels are unbounded. Returns Err(ThreadError::Disconnected) once the channel is closed and Err(ThreadError::NotSendable) for a value that cannot cross threads.

Parameters#

NameType
txSender
valueT

Returns#

Result<unit, ThreadError>

Examples#

use thread::{channel, send, recv};
use tests::assert;
let (tx, rx) = match channel() {
    Result::Ok(pair) => pair,
    Result::Err(_) => panic "channel failed",
};
let _ = send(tx, [1, 2, 3]);
let v = match recv(rx) {
    Result::Ok(v) => v,
    Result::Err(_) => [0, 0, 0],
};
assert!(v[2] == 3);

See also#

  • spawn: Runs f(arg) on another OS thread and returns a handle to it.
  • join: Waits for the thread to finish and returns the value its function returned.
  • detach: Lets the thread run to completion without being joined.
  • channel: Creates an unbounded channel and returns its (Sender, Receiver) ends.
  • 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