Function in thread compiler

try_read

fn try_read<A, B>(RwLock lock, A -> B f) -> Result<B, ThreadError>
Import
use thread::{try_read};
Source: compiler/src/builtin_docs/thread.hy

Like with_read, but returns Err(ThreadError::WouldBlock) instead of waiting when a writer holds the lock.

Parameters#

NameType
lockRwLock
fA -> B

Returns#

Result<B, ThreadError>

Examples#

use thread::{rwlock, try_read};
use tests::assert;
let lock = match rwlock(5) {
    Result::Ok(l) => l,
    Result::Err(_) => panic "rwlock failed",
};
assert!(match try_read(lock, fn (int n) => n * 2) { Result::Ok(v) => v == 10, Result::Err(_) => false });

See also#

  • thread::with_read
  • 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.
  • recv: Takes the next value from the channel, waiting until one arrives.
  • try_send: Sends value without waiting.
↑ ↓ navigate ↵ open