recv
fn recv<T>(Receiver rx) -> Result<T, ThreadError> Import
Source: use thread::{recv}; compiler/src/builtin_docs/thread.hy Takes the next value from the channel, waiting until one arrives.
Returns Err(ThreadError::Disconnected) when the channel is closed and
every value has been received. Inside a task::scope, only the waiting
task is suspended.
Parameters#
| Name | Type |
|---|---|
rx | Receiver |
Returns#
Result<T, ThreadError>
Examples#
use thread::{channel, send, recv, close, ThreadError};
use tests::assert;
let (tx, rx) = match channel() {
Result::Ok(pair) => pair,
Result::Err(_) => panic "channel failed",
};
let _ = send(tx, "last");
let _ = close(tx);
assert!(match recv(rx) { Result::Ok(s) => s == "last", Result::Err(_) => false });
let done = match recv(rx) {
Result::Err(ThreadError::Disconnected) => true,
default => false,
};
assert!(done);
See also#
task::scopespawn: Runsf(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.send: Sends a copy ofvalueon the channel.try_send: Sendsvaluewithout waiting.try_recv: Takes the next value if there is one, without waiting.