blob: 359bafa03751c9aceb536a126d65a177cc545b41 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import { E_ALREADY_LOCKED } from './errors';
import MutexInterface from './mutex';
import type { SemaphoreInterface } from './semaphoreinterface';
import { withTimeout } from './withtimeout';
export function tryAcquire(
mutex: MutexInterface,
alreadyAcquiredError?: Error
): MutexInterface;
export function tryAcquire(
semaphore: SemaphoreInterface,
alreadyAcquiredError?: Error
): SemaphoreInterface;
// eslint-disable-next-lisne @typescript-eslint/explicit-module-boundary-types
export function tryAcquire(
sync: MutexInterface | SemaphoreInterface,
alreadyAcquiredError = E_ALREADY_LOCKED
): typeof sync {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return withTimeout(sync as any, 0, alreadyAcquiredError);
}
|