SemaphoreProvider class can be derived from any ISemaphoreAdapter or IDatabaseSemaphoreAdapter.

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

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

Implements

Constructors

  • Parameters

    Returns SemaphoreProvider

    import { KyselySemaphoreAdapter } from "@daiso-tech/core/semaphore/kysely-semaphore-adapter";
    import { SemaphoreProvider } from "@daiso-tech/core/semaphore";
    import { Serde } from "@daiso-tech/core/serde";
    import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter";
    import Sqlite from "better-sqlite3";
    import { Kysely, SqliteDialect } from "kysely";

    const semaphoreAdapter = new KyselySemaphoreAdapter({
    kysely: new Kysely({
    dialect: new SqliteDialect({
    database: new Sqlite("local.db"),
    }),
    });
    });
    // You need initialize the adapter once before using it.
    await semaphoreAdapter.init();

    const serde = new Serde(new SuperJsonSerdeAdapter())
    const lockProvider = new SemaphoreProvider({
    serde,
    adapter: semaphoreAdapter,
    });

Methods