-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BasicLockable, Lockable and TimedLockable interfaces
- Loading branch information
1 parent
d96b481
commit 8c8912d
Showing
9 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* The base interface for types that provide exclusive | ||
* blocking for agents (i.e. main thread, workers). | ||
*/ | ||
export interface BasicLockable { | ||
/** | ||
* Blocks until a lock can be acquired for the current agent. | ||
* If an exception is thrown, no lock is acquired. | ||
*/ | ||
lock(): Promise<void>; | ||
|
||
/** | ||
* Releases the lock held by the current agent. | ||
*/ | ||
unlock(): void | Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { BasicLockable } from "./basicLockable"; | ||
|
||
/** | ||
* Extends the {@link BasicLockable} interface to include attempted locking. | ||
*/ | ||
export interface Lockable extends BasicLockable { | ||
/** | ||
* Attempts to acquire the lock for the current agent | ||
* without blocking until acquired. If an exception | ||
* is thrown, no lock is obtained. | ||
* | ||
* @returns `true` if the lock was acquired, `false` otherwise. | ||
*/ | ||
tryLock(): boolean | Promise<boolean>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Lockable } from "./lockable"; | ||
|
||
/** | ||
* Extends the {@link Lockable} interface to include timed blocking. | ||
*/ | ||
export interface TimedLockable extends Lockable { | ||
/** | ||
* Blocks for the provided duration or until a lock is acquired. | ||
* | ||
* @returns `true` if the lock was acquired, `false` otherwise. | ||
*/ | ||
tryLockFor(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. | ||
*/ | ||
tryLockUntil(timestamp: number): Promise<boolean>; | ||
} |