From 03166e7e576eb3d67cae65415e57b327c2cafd46 Mon Sep 17 00:00:00 2001 From: havelessbemore Date: Thu, 9 May 2024 23:29:27 -0400 Subject: [PATCH] Add the SharedTimedLockable interface --- src/index.ts | 1 + src/types/sharedTimedLockable.d.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/types/sharedTimedLockable.d.ts diff --git a/src/index.ts b/src/index.ts index c9aa088..ddf81d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ export { BasicLockable } from "./types/basicLockable"; export { type CVStatus, CV_OK, CV_TIMED_OUT } from "./types/cvStatus"; export { Lockable } from "./types/lockable"; export { SharedLockable } from "./types/sharedLockable"; +export { SharedTimedLockable } from "./types/sharedTimedLockable"; export { TimedLockable } from "./types/timedLockable"; // Errors diff --git a/src/types/sharedTimedLockable.d.ts b/src/types/sharedTimedLockable.d.ts new file mode 100644 index 0000000..ba49e3a --- /dev/null +++ b/src/types/sharedTimedLockable.d.ts @@ -0,0 +1,20 @@ +import { SharedLockable } from "./sharedLockable"; + +/** + * Extends the {@link SharedLockable} interface to include timed blocking. + */ +export interface SharedTimedLockable extends SharedLockable { + /** + * Blocks for the provided duration or until a lock is acquired. + * + * @returns `true` if the lock was acquired, `false` otherwise. + */ + tryLockSharedFor(timeout: number): Promise; + + /** + * Blocks until the provided timestamp is reached or a lock is acquired. + * + * @returns `true` if the lock was acquired, `false` otherwise. + */ + tryLockSharedUntil(timestamp: number): Promise; +}