try_write
fn try_write<A, B>(RwLock lock, A -> (A, B) f) -> Result<B, ThreadError> Import
Source: use thread::{try_write}; compiler/src/builtin_docs/thread.hy Like with_write, but returns Err(ThreadError::WouldBlock) instead of waiting when the lock is held.
Parameters#
| Name | Type |
|---|---|
lock | RwLock |
f | A -> (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_writespawn: 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.send: Sends a copy ofvalueon the channel.recv: Takes the next value from the channel, waiting until one arrives.try_send: Sendsvaluewithout waiting.