LockProvider class can be derived from any ILockAdapter or IDatabaseLockAdapter.

Note the ILock instances created by the LockProvider class are serializable and deserializable, allowing them to be seamlessly transferred across different servers, processes, and databases. This can be done directly using IFlexibleSerde or indirectly through components that rely on IFlexibleSerde internally.

IMPORT_PATH: "@daiso-tech/core/lock"

Implements

Constructors

  • Parameters

    Returns LockProvider

    import { SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
    import { LockProvider } from "@daiso-tech/core/lock";
    import { KeyPrefixer } from "@daiso-tech/core/utilities";
    import { Serde } from "@daiso-tech/core/serde";
    import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
    import Sqlite from "better-sqlite3";

    const database = new Sqlite("local.db");
    const lockAdapter = new SqliteLockAdapter({
    database,
    });
    // You need initialize the adapter once before using it.
    await lockAdapter.init();

    const serde = new Serde(new SuperJsonSerdeAdapter())
    const lockProvider = new LockProvider({
    keyPrefixer: new KeyPrefixer("lock"),
    serde,
    adapter: lockAdapter,
    });

Methods

  • Parameters

    Returns ILock

    import { LockProvider } from "@daiso-tech/core/lock";
    import { MemoryLockAdapter } from "@daiso-tech/core/lock/adapters";
    import { KeyPrefixer } from "@daiso-tech/core/utilities";
    import { Serde } from "@daiso-tech/core/serde";
    import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";

    const lockProvider = new LockProvider({
    adapter: new MemoryLockAdapter(),
    keyPrefixer: new KeyPrefixer("lock"),
    serde: new Serde(new SuperJsonSerdeAdapter())
    });

    const lock = lockProvider.create("a");