Function in thread compiler

close

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

Closes the channel: no more sends.

Later send / try_send calls fail with Disconnected. Receivers still get the values already queued, then Disconnected. Closing twice is fine.

Parameters#

NameType
txSender

Returns#

Result<unit, ThreadError>

Examples#

use thread::{channel, close, send, ThreadError};
use tests::assert;
let (tx, rx) = match channel() {
    Result::Ok(pair) => pair,
    Result::Err(_) => panic "channel failed",
};
assert!(match close(tx) { Result::Ok(_) => true, Result::Err(_) => false });
let refused = match send(tx, 1) {
    Result::Err(ThreadError::Disconnected) => true,
    default => false,
};
assert!(refused);

See also#

  • thread::send
  • thread::try_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.
↑ ↓ navigate ↵ open