Skip to content

Commit

Permalink
Add the SharedTimedLockable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
havelessbemore committed May 10, 2024
1 parent a1b0187 commit 03166e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/types/sharedTimedLockable.d.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>;

/**
* 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<boolean>;
}

0 comments on commit 03166e7

Please sign in to comment.