import { KyselySemaphoreAdapter } from "@daiso-tech/core/semaphore/kysely-semaphore-adapter";
import { SemaphoreFactory } 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 SemaphoreFactory({
serde,
adapter: semaphoreAdapter,
});
The create method is used to create an instance of ISemaphore.
SemaphoreFactoryclass can be derived from anyISemaphoreAdapterorIDatabaseSemaphoreAdapter.Note the
ISemaphoreinstances created by theSemaphoreFactoryclass are serializable and deserializable, allowing them to be seamlessly transferred across different servers, processes, and databases. This can be done directly usingISerderRegisteror indirectly through components that rely onISerderRegisterinternally.IMPORT_PATH:
"@daiso-tech/core/semaphore"