Function in thread compiler

try_write

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

Like with_write, but returns Err(ThreadError::WouldBlock) instead of waiting when the lock is held.

Parameters#

NameType
lockRwLock
fA -> (A, B)

Returns#

Result<B, ThreadError>

Examples#

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

See also#

  • thread::with_write
  • 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