@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
76 lines (75 loc) • 3.14 kB
TypeScript
/**
* @module Lock
*/
import { TimeSpan } from "../../../../utilities/_module-exports.js";
import { type Key, type AsyncLazy, type OneOrMore, type Result } from "../../../../utilities/_module-exports.js";
import { KeyAlreadyAcquiredLockError, type LockAquireBlockingSettings, type LockEventMap } from "../../../../lock/contracts/_module-exports.js";
import { type ILock, type ILockAdapter } from "../../../../lock/contracts/_module-exports.js";
import { LazyPromise } from "../../../../async/_module-exports.js";
import type { IEventDispatcher } from "../../../../event-bus/contracts/_module-exports.js";
import type { LockState } from "../../../../lock/implementations/derivables/lock-provider/lock-state.js";
/**
* @internal
*/
export type ISerializedLock = {
key: string;
expirationInMs: number | null;
owner: string;
ttlInMs: number | null;
};
/**
* @internal
*/
export type LockSettings = {
createLazyPromise: <TValue = void>(asyncFn: () => PromiseLike<TValue>) => LazyPromise<TValue>;
serdeTransformerName: string;
adapter: ILockAdapter;
lockState: LockState;
eventDispatcher: IEventDispatcher<LockEventMap>;
key: Key;
owner: OneOrMore<string>;
ttl: TimeSpan | null;
expirationInMs?: number | null;
defaultBlockingInterval: TimeSpan;
defaultBlockingTime: TimeSpan;
defaultRefreshTime: TimeSpan;
};
/**
* @internal
*/
export declare class Lock implements ILock {
/**
* @internal
*/
static _internal_serialize(deserializedValue: Lock): ISerializedLock;
private readonly createLazyPromise;
private readonly adapter;
private readonly lockState;
private readonly eventDispatcher;
private readonly key;
private readonly owner;
private readonly ttl;
private readonly defaultBlockingInterval;
private readonly defaultBlockingTime;
private readonly defaultRefreshTime;
private readonly serdeTransformerName;
constructor(settings: LockSettings);
_internal_getSerdeTransformerName(): string;
run<TValue = void>(asyncFn: AsyncLazy<TValue>): LazyPromise<Result<TValue, KeyAlreadyAcquiredLockError>>;
runOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>): LazyPromise<TValue>;
runBlocking<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?: LockAquireBlockingSettings): LazyPromise<Result<TValue, KeyAlreadyAcquiredLockError>>;
runBlockingOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?: LockAquireBlockingSettings): LazyPromise<TValue>;
acquire(): LazyPromise<boolean>;
acquireOrFail(): LazyPromise<void>;
acquireBlocking(settings?: LockAquireBlockingSettings): LazyPromise<boolean>;
acquireBlockingOrFail(settings?: LockAquireBlockingSettings): LazyPromise<void>;
release(): LazyPromise<boolean>;
releaseOrFail(): LazyPromise<void>;
forceRelease(): LazyPromise<void>;
isExpired(): LazyPromise<boolean>;
isLocked(): LazyPromise<boolean>;
refresh(ttl?: TimeSpan): LazyPromise<boolean>;
refreshOrFail(ttl?: TimeSpan): LazyPromise<void>;
getRemainingTime(): LazyPromise<TimeSpan | null>;
getOwner(): LazyPromise<string>;
}