Receiver
class Receiver Import
Source: use thread::{Receiver}; 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#
thread::channelthread::Senderthread::recvThread: A handle to a function running on another OS thread, fromspawn.Mutex: A mutual-exclusion lock that owns a value, made bymutex.RwLock: A readers-writer lock that owns a value, made byrwlock.