import { AsyncSubscription } from '@deepkit/core-rxjs' ; import { injectable } from '@deepkit/injector' ; import { Broker } from './broker' ; export class AppLock { constructor ( protected subscription ) { } async release ( ) { await this . subscription . unsubscribe ( ) ; } } /**
 * An global application lock (across workers, processes, and nodes).
 * It provides a way to acquire locks on the central broker process atomically.
*/ @ injectable export class AppLocker { constructor ( protected broker ) { } param id param ttl param timeout example public async acquireLock ( id , ttl = 0 , timeout = 0 ) { return new AppLock ( await this . broker . lock ( id , ttl , timeout ) ) ; } param id param ttl public async tryLock ( id , ttl = 0 ) { const subscription = await this . broker . tryLock ( id , ttl ) ; if ( ! subscription ) return subscription ; return new AppLock ( subscription ) ; } /**
     * Returns true if the lock is already aquired by someone.
    */ public async isLocked ( id ) { return this . broker . isLocked ( id ) ; } }