Class in thread compiler

Receiver

class Receiver
Import
use thread::{Receiver};
Source: compiler/src/builtin_docs/thread.hy

The receiving half of a channel made by channel.

Like Sender, a Receiver can be passed to other threads; each value sent is received exactly once, by whichever recv takes it first.

Examples#

use thread::{channel, send, try_recv, Receiver, ThreadError};
use tests::assert;
let (tx, rx) = match channel() {
    Result::Ok(pair) => pair,
    Result::Err(_) => panic "channel failed",
};
let r: Receiver = rx;
let empty = match try_recv(r) {
    Result::Err(ThreadError::WouldBlock) => true,
    default => false,
};
assert!(empty);
let _ = send(tx, 1);
assert!(match try_recv(r) { Result::Ok(v) => v == 1, Result::Err(_) => false });

See also#

↑ ↓ navigate ↵ open