Skip to content

UdpBindLock

Defined in: packages/app-system/src/async/udp-bind-lock.ts:75

A class that provides a mechanism to ensure that only one instance of a process is running at a time by attempting to bind to a specific UDP port.

This is useful for preventing multiple instances of a script or application from running simultaneously.

Note: The lock is automatically released when the process exits, but it is recommended to call release explicitly when the lock is no longer needed.

Example usage:

const lock = new UdpBindLock({
udpSocketType: "udp4",
udpBindPort: 12345,
});
const acquired = await lock.tryAcquire();
if (!acquired) {
console.error("Another instance is already running.");
process.exit(1);
}
// ... application logic ...
await lock.release();
  • ILock

new UdpBindLock(config, options?): UdpBindLock

Defined in: packages/app-system/src/async/udp-bind-lock.ts:79

UdpBindLockConfig

UdpBindLockOptions

UdpBindLock

get locked(): boolean

Defined in: packages/app-system/src/async/udp-bind-lock.ts:86

Indicates whether the lock is currently held.

boolean

ILock.locked

lock(signal?): Promise<void>

Defined in: packages/app-system/src/async/udp-bind-lock.ts:94

Acquires the lock, waiting if necessary until it is available.

AbortSignal | null

An optional AbortSignal to cancel the acquire operation.

Promise<void>

A promise that resolves when the lock is acquired.

ILock.lock


tryLock(): Promise<boolean>

Defined in: packages/app-system/src/async/udp-bind-lock.ts:90

Attempts to acquire the lock without waiting.

Promise<boolean>

True if the lock was successfully acquired, false otherwise.

ILock.tryLock


unlock(): Promise<void>

Defined in: packages/app-system/src/async/udp-bind-lock.ts:101

Releases the lock.

Promise<void>

ILock.unlock