-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from coligo-tech/dev
Add types
- Loading branch information
Showing
5 changed files
with
57 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
|
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,42 @@ | ||
import { Redis } from 'ioredis'; | ||
|
||
/** | ||
* Release the lock only if it has the same lockValue as acquireLock sets it. | ||
* This will not release an already released token. | ||
*/ | ||
type ReleaseFunction = () => Promise<void>; | ||
|
||
interface acquireOptions { | ||
/** | ||
* Time interval at which attempt to acquire the lock. | ||
* | ||
* @default 100 | ||
*/ | ||
retryTimeMillis?: number; | ||
|
||
/** | ||
* Time span after which the acquired lock times out and is released. | ||
*/ | ||
timeoutMillis?: number; | ||
|
||
/** | ||
* Time span after which will not attempt to acquire the lock, and the `lock` function will fail. | ||
*/ | ||
failAfterMillis?: number; | ||
} | ||
|
||
/** | ||
* Acquire mutex lock on the given resource name. | ||
* If the lock is already acquired, wait until it's free and acquire it. | ||
* | ||
* @param client ioredis instance. | ||
* @param lockName the name of the lock to be acquired. | ||
* @param options lock acquire options. | ||
* | ||
* @returns a promise that resolves with release function. | ||
*/ | ||
export function lock( | ||
client: Redis, | ||
lockName: string, | ||
options: acquireOptions | ||
): Promise<ReleaseFunction>; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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