Lyricdev
GitHub

class RwLock

pub class RwLock<T>

A value that readers share and a writer holds alone.

A writer that waits goes first: readers that come after it wait for it.

Methods

pub static fn new(value: T): RwLock<T>

Creates a lock that holds value.

pub fn read<R, E :: [Error]>(body: fn(T) -> R throws E): R throws [E, Cancelled]

Runs body with the value while no writer holds the lock — other readers may — and returns what body returns.

Errors

Throws what body throws, and Cancelled when the task is cancelled during the wait.

pub fn write<R, E :: [Error]>(body: fn(&T) -> R throws E): R throws [E, Cancelled]

Runs body while the running task alone holds the lock — no reader, no other writer — and returns what body returns.

The body takes the value's place, as Mutex.lock's does.

Errors

Throws what body throws, and Cancelled when the task is cancelled during the wait.