Function in thread compiler

recv

fn recv<T>(Receiver rx) -> Result<T, ThreadError>
Import
use thread::{recv};
Source: 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#

NameType
rxReceiver

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::scope
  • 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.
  • send: Sends a copy of value on the channel.
  • try_send: Sends value without waiting.
  • try_recv: Takes the next value if there is one, without waiting.
↑ ↓ navigate ↵ open