close
fn close(Sender tx) -> Result<unit, ThreadError> Import
Source: use thread::{close}; 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#
| Name | Type |
|---|---|
tx | Sender |
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::sendthread::try_sendspawn: 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.recv: Takes the next value from the channel, waiting until one arrives.try_recv: Takes the next value if there is one, without waiting.