Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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>;
}

§Type Parameters

§
Resource extends object = {}
[src]

§Constructors

§
new Mutex(resource: Resource)
[src]

§Properties

§
poisonedError: undefined | Error
[src]
§
queueTail: undefined | Promise<void>
[src]

§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<{
resource: Resource;
release(): void;
}
>
[src]

Blocks until the lock is obtained, then returns the proxied value and a callback to release the lock.

§
tryUseSync<Result = void>(f: (resource: Resource) => Result): Result | void
[src]

Runs a synchronous callback with exclusive access to the resource if is immediately available, otherwise returns undefined.

§
use<Result = void>(f: (resource: Resource) => Result): Promise<Result>
[src]

Runs an async callback with exclusive access to the resource when it is next available, FIFO.