Expand description
Constructors§
Properties§
§
public inner: TWriteThis is public so inner object can be accessed directly ONLY SAFE in sync context
Methods§
Source§scopedRead<R>(fn: (t: TRead) => Promise<R>): Promise<R>
scopedRead<R>(fn: (t: TRead) => Promise<R>): Promise<R>
Acquire a read (shared) lock and call fn with the value. Release the lock when fn returns or throws.
Source§scopedWrite<R>(
fn: (t: TWrite, setter: (t: TWrite) => TWrite) => Promise<R>,
): Promise<R>
scopedWrite<R>(
fn: (t: TWrite, setter: (t: TWrite) => TWrite) => Promise<R>,
): Promise<R>
Acquire a write (exclusive) lock and call fn with the value. Release the lock when fn returns or throws.
fn takes a setter function as second parameter, which you can use to update the value like x = set(newX)
Ensure you have exclusive access in concurrent code
Only guaranteed if no one else has reference to the inner object
It can take a second type parameter to specify interface with write methods