Mutex
import { Mutex } from "https://raw.githubusercontent.com/jeremyBanks/database/0.1.0-dev/_common/mutex.ts";
Simple async mutex, with object access enforced by revokable proxies. Errors unlock the mutex, they don't poison it.
class Mutex<Resource extends object = {}> { }
constructor(resource: Resource);
private poisonedError: undefined | Error;
private queueTail: undefined | Promise<void>;
private poison(error: Error);
async dispose(): Promise<void>;
async lock(): Promise<{
resource: Resource;
release(): void;
}>;tryUseSync<Result = void>(f: (resource: Resource) => Result): Result | void;
async use<Result = void>(f: (resource: Resource) => Result): Promise<Result>;
§Properties
§Methods
§
poison(error: Error) private
[src]Marks the mutex as "poisoned" with a given error, that will be raised on any future attempts to use the mutex. For internal use when the mutex is being disposed of.
§
dispose(): Promise<void>
[src]Allows any currently-queued operations execute, then poisons the mutex.
§
lock(): Promise<{
[src]resource: Resource;
release(): void;
}>Blocks until the lock is obtained, then returns the proxied value and a callback to release the lock.