@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.
77 lines (76 loc) • 2.75 kB
TypeScript
/**
* @module Lock
*/
import { type IEventDispatcher } from "../../../../event-bus/contracts/_module.js";
import { type ILock, type ILockAdapter, type LockAquireBlockingSettings, type LockEventMap, type ILockState, type IDatabaseLockAdapter } from "../../../../lock/contracts/_module.js";
import { type Key, type Namespace } from "../../../../namespace/_module.js";
import { type ITask } from "../../../../task/contracts/_module.js";
import { type ITimeSpan } from "../../../../time-span/contracts/_module.js";
import { TimeSpan } from "../../../../time-span/implementations/_module.js";
import { type AsyncLazy } from "../../../../utilities/_module.js";
/**
* @internal
*/
export type ISerializedLock = {
version: "1";
key: string;
lockId: string;
ttlInMs: number | null;
};
/**
* @internal
*/
export type LockSettings = {
serdeTransformerName: string;
namespace: Namespace;
adapter: ILockAdapter;
originalAdapter: IDatabaseLockAdapter | ILockAdapter;
eventDispatcher: IEventDispatcher<LockEventMap>;
key: Key;
lockId: string;
ttl: TimeSpan | null;
defaultBlockingInterval: TimeSpan;
defaultBlockingTime: TimeSpan;
defaultRefreshTime: TimeSpan;
};
/**
* @internal
*/
export declare class Lock implements ILock {
/**
* @internal
*/
static _internal_serialize(deserializedValue: Lock): ISerializedLock;
private readonly namespace;
private readonly adapter;
private readonly originalAdapter;
private readonly eventDispatcher;
private readonly _key;
private readonly lockId;
private _ttl;
private readonly defaultBlockingInterval;
private readonly defaultBlockingTime;
private readonly defaultRefreshTime;
private readonly serdeTransformerName;
constructor(settings: LockSettings);
_internal_getNamespace(): Namespace;
_internal_getSerdeTransformerName(): string;
_internal_getAdapter(): IDatabaseLockAdapter | ILockAdapter;
runOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>): ITask<TValue>;
runBlockingOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?: LockAquireBlockingSettings): ITask<TValue>;
private handleUnexpectedError;
private handleDispatch;
acquire(): ITask<boolean>;
acquireOrFail(): ITask<void>;
acquireBlocking(settings?: LockAquireBlockingSettings): ITask<boolean>;
acquireBlockingOrFail(settings?: LockAquireBlockingSettings): ITask<void>;
release(): ITask<boolean>;
releaseOrFail(): ITask<void>;
forceRelease(): ITask<boolean>;
refresh(ttl?: ITimeSpan): ITask<boolean>;
refreshOrFail(ttl?: ITimeSpan): ITask<void>;
get key(): string;
get id(): string;
get ttl(): TimeSpan | null;
getState(): ITask<ILockState>;
}