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();Implements
Section titled “Implements”ILock
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new UdpBindLock(
config,options?):UdpBindLock
Defined in: packages/app-system/src/async/udp-bind-lock.ts:79
Parameters
Section titled “Parameters”config
Section titled “config”options?
Section titled “options?”Returns
Section titled “Returns”UdpBindLock
Accessors
Section titled “Accessors”locked
Section titled “locked”Get Signature
Section titled “Get Signature”get locked():
boolean
Defined in: packages/app-system/src/async/udp-bind-lock.ts:86
Indicates whether the lock is currently held.
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”ILock.locked
Methods
Section titled “Methods”lock()
Section titled “lock()”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.
Parameters
Section titled “Parameters”signal?
Section titled “signal?”AbortSignal | null
An optional AbortSignal to cancel the acquire operation.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the lock is acquired.
Implementation of
Section titled “Implementation of”ILock.lock
tryLock()
Section titled “tryLock()”tryLock():
Promise<boolean>
Defined in: packages/app-system/src/async/udp-bind-lock.ts:90
Attempts to acquire the lock without waiting.
Returns
Section titled “Returns”Promise<boolean>
True if the lock was successfully acquired, false otherwise.
Implementation of
Section titled “Implementation of”ILock.tryLock
unlock()
Section titled “unlock()”unlock():
Promise<void>
Defined in: packages/app-system/src/async/udp-bind-lock.ts:101
Releases the lock.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”ILock.unlock