UNPKG

@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.

51 lines (50 loc) 1.65 kB
/** * @module Lock */ import type { IDeinitizable, TimeSpan } from "../../../../utilities/_module-exports.js"; import { type ILockAdapter, type LockRefreshResult } from "../../../../lock/contracts/_module-exports.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"` * @group Adapters */ export type MemoryLockData = { owner: string; hasExpiration: true; timeoutId: string | number | NodeJS.Timeout; } | { owner: string; hasExpiration: false; }; /** * Note the `MemoryLockAdapter` is limited to single process usage and cannot be shared across multiple servers or different processes. * This adapter is meant to be used for testing. * * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"` * @group Adapters */ export declare class MemoryLockAdapter implements ILockAdapter, IDeinitizable { private readonly map; /** * @example * ```ts * import { MemoryLockAdapter } from "@daiso-tech/core/lock/adapters"; * * const lockAdapter = new MemoryLockAdapter(); * ``` * You can also provide an `Map`. * @example * ```ts * import { MemoryLockAdapter } from "@daiso-tech/core/lock/adapters"; * * const map = new Map<any, any>(); * const lockAdapter = new MemoryLockAdapter(map); * ``` */ constructor(map?: Map<string, MemoryLockData>); deInit(): Promise<void>; acquire(key: string, owner: string, ttl: TimeSpan | null): Promise<boolean>; release(key: string, owner: string): Promise<boolean>; forceRelease(key: string): Promise<boolean>; refresh(key: string, owner: string, ttl: TimeSpan): Promise<LockRefreshResult>; }