Function in thread compiler

try_send

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

Sends value without waiting.

Channels are unbounded, so this behaves exactly like send: it fails only with Disconnected (closed channel) or NotSendable.

Parameters#

NameType
txSender
valueT

Returns#

Result<unit, ThreadError>

Examples#

use thread::{channel, try_send, try_recv};
use tests::assert;
let (tx, rx) = match channel() {
    Result::Ok(pair) => pair,
    Result::Err(_) => panic "channel failed",
};
assert!(match try_send(tx, 7) { Result::Ok(_) => true, Result::Err(_) => false });
assert!(match try_recv(rx) { Result::Ok(v) => v == 7, Result::Err(_) => false });

See also#

  • thread::send
  • 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_recv: Takes the next value if there is one, without waiting.
  • close: Closes the channel: no more sends.
↑ ↓ navigate ↵ open