-
-
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.
- Loading branch information
1 parent
281c622
commit 0077625
Showing
3 changed files
with
66 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
export = Mutex; | ||
|
||
declare class Mutex { | ||
/** | ||
* Gets the globally registered mutex corresponding to `name`. | ||
* If a mutex has not already been created for `name`, one will | ||
* be created and returned. | ||
* | ||
* @param name The name of the mutex to retrieve. | ||
*/ | ||
static getMutex(name: string): Mutex; | ||
|
||
/** | ||
* Creates a new Mutex object. | ||
* | ||
* @param name An optional name used to identify | ||
* the resource the mutex locks. | ||
*/ | ||
constructor(name?: string); | ||
|
||
/** | ||
* Attempts to acquire a lock on the mutex. If the lock can be | ||
* acquired, it will set `.isLocked` to `true`, and will resolve | ||
* the promise. | ||
* | ||
* If the optional argument, `timeout`, is `0`, the call will wait | ||
* indefinitely until the lock is released. | ||
* | ||
* If `timeout` is a value greater than `0`, the promise will be | ||
* rejected after the number of milliseconds specified in | ||
* `timeout` have elapsed. | ||
* | ||
* @param timeout The number of milliseconds to wait for the lock | ||
* to be acquired. | ||
*/ | ||
wait(timeout?: number): Promise<void>; | ||
|
||
/** | ||
* Releases the existing lock. If there are any consumers that have | ||
* called `.wait(timeout)` and are still waiting, the first to have | ||
* called `.wait(timeout)` will acquire the lock. | ||
* | ||
* Once there are no more consumers waiting to acquire the lock, | ||
* `.isLocked` will be set to `false`. | ||
* | ||
* **Note**: it is important to always call `.release()` once | ||
* finished accessing the resource. If not, nothing else will | ||
* be able to acquire the lock. | ||
*/ | ||
release(): void; | ||
|
||
/** | ||
* Returns a boolean value indicating whether or not the mutex is locked. | ||
*/ | ||
get isLocked(): boolean; | ||
|
||
/** | ||
* Returns the name of the mutex. | ||
*/ | ||
get name(): string; | ||
} |
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,2 @@ | ||
export { Mutex }; | ||
import Mutex = require("./Mutex"); |