@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.
92 lines (91 loc) • 3.78 kB
TypeScript
/**
* @module SharedLock
*/
import { type IEventDispatcher } from "../../../../event-bus/contracts/event-bus.contract.js";
import { type Key, type Namespace } from "../../../../namespace/_module.js";
import { type IDatabaseSharedLockAdapter, type ISharedLock, type ISharedLockAdapter, type ISharedLockState, type SharedLockAquireBlockingSettings, type SharedLockEventMap } from "../../../../shared-lock/contracts/_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 ISerializedSharedLock = {
version: "1";
key: string;
lockId: string;
limit: number;
ttlInMs: number | null;
};
/**
* @internal
*/
export type SharedLockSettings = {
serdeTransformerName: string;
namespace: Namespace;
adapter: ISharedLockAdapter;
originalAdapter: IDatabaseSharedLockAdapter | ISharedLockAdapter;
eventDispatcher: IEventDispatcher<SharedLockEventMap>;
limit: number;
key: Key;
lockId: string;
ttl: TimeSpan | null;
defaultBlockingInterval: TimeSpan;
defaultBlockingTime: TimeSpan;
defaultRefreshTime: TimeSpan;
};
/**
* @internal
*/
export declare class SharedLock implements ISharedLock {
/**
* @internal
*/
static _internal_serialize(deserializedValue: SharedLock): ISerializedSharedLock;
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;
private readonly limit;
constructor(settings: SharedLockSettings);
_internal_getNamespace(): Namespace;
_internal_getSerdeTransformerName(): string;
_internal_getAdapter(): IDatabaseSharedLockAdapter | ISharedLockAdapter;
runReaderOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>): ITask<TValue>;
runReaderBlockingOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?: SharedLockAquireBlockingSettings): ITask<TValue>;
private handleUnexpectedError;
private handleDispatch;
acquireReader(): ITask<boolean>;
acquireReaderOrFail(): ITask<void>;
acquireReaderBlocking(settings?: SharedLockAquireBlockingSettings): ITask<boolean>;
acquireReaderBlockingOrFail(settings?: SharedLockAquireBlockingSettings): ITask<void>;
releaseReader(): ITask<boolean>;
releaseReaderOrFail(): ITask<void>;
forceReleaseAllReaders(): ITask<boolean>;
refreshReader(ttl?: ITimeSpan): ITask<boolean>;
refreshReaderOrFail(ttl?: ITimeSpan): ITask<void>;
runWriterOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>): ITask<TValue>;
runWriterBlockingOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?: SharedLockAquireBlockingSettings): ITask<TValue>;
acquireWriter(): ITask<boolean>;
acquireWriterOrFail(): ITask<void>;
acquireWriterBlocking(settings?: SharedLockAquireBlockingSettings): ITask<boolean>;
acquireWriterBlockingOrFail(settings?: SharedLockAquireBlockingSettings): ITask<void>;
releaseWriter(): ITask<boolean>;
releaseWriterOrFail(): ITask<void>;
forceReleaseWriter(): ITask<boolean>;
refreshWriter(ttl?: ITimeSpan): ITask<boolean>;
refreshWriterOrFail(ttl?: ITimeSpan): ITask<void>;
get key(): string;
get id(): string;
get ttl(): TimeSpan | null;
forceRelease(): ITask<boolean>;
getState(): ITask<ISharedLockState>;
}