aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/vendor/async-mutex/tryaquire.ts
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-08-20 12:46:01 +0000
committerLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-08-20 12:46:01 +0000
commit80d0342636056bc839517b64fd11708abea70237 (patch)
tree99c2505b924ab47bc21b215a43cdac2c37c9facf /src/lib/vendor/async-mutex/tryaquire.ts
parentdddef149aea597a145e3717b2c461b251e0f6a8d (diff)
downloadcrunched-80d0342636056bc839517b64fd11708abea70237.tar.gz
crunched-80d0342636056bc839517b64fd11708abea70237.tar.bz2
crunched-80d0342636056bc839517b64fd11708abea70237.tar.lz
crunched-80d0342636056bc839517b64fd11708abea70237.zip

feat: locks :3

Diffstat (limited to 'src/lib/vendor/async-mutex/tryaquire.ts')
-rw-r--r--src/lib/vendor/async-mutex/tryaquire.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/vendor/async-mutex/tryaquire.ts b/src/lib/vendor/async-mutex/tryaquire.ts
new file mode 100644
index 0000000..359bafa
--- /dev/null
+++ b/src/lib/vendor/async-mutex/tryaquire.ts
@@ -0,0 +1,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);
+}