import { KyselySharedLockAdapter } from "@daiso-tech/core/shared-lock/kysely-shared-lock-adapter";
import { SharedLockProvider } from "@daiso-tech/core/shared-lock";
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 sharedLockAdapter = new KyselySharedLockAdapter({
kysely: new Kysely({
dialect: new SqliteDialect({
database: new Sqlite("local.db"),
}),
});
});
// You need initialize the adapter once before using it.
await sharedLockAdapter.init();
const serde = new Serde(new SuperJsonSerdeAdapter())
const lockProvider = new SharedLockProvider({
serde,
adapter: sharedLockAdapter,
});
You can listen to the following SharedLockEventMap of all ISharedLock instances created by the ISharedLockProvider.
To understand how this method works, refer to IEventListenable .
You can listen to the following SharedLockEventMap of all ISharedLock instances created by the ISharedLockProvider.
To understand how this method works, refer to IEventListenable .
import { SharedLockProvider } from "@daiso-tech/core/shared-lock";
import { MemorySharedLockAdapter } from "@daiso-tech/core/shared-lock/memory-shared-lock-adapter";
import { Namespace } from "@daiso-tech/core/namespace";
import { Serde } from "@daiso-tech/core/serde";
import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter";
const lockProvider = new SharedLockProvider({
adapter: new MemorySharedLockAdapter(),
namespace: new Namespace("shared_lock"),
serde: new Serde(new SuperJsonSerdeAdapter())
});
const sharedLock = lockProvider.create("a");
You can listen to the following SharedLockEventMap of all ISharedLock instances created by the ISharedLockProvider.
To understand how this method works, refer to IEventListenable .
You can listen to the following SharedLockEventMap of all ISharedLock instances created by the ISharedLockProvider.
To understand how this method works, refer to IEventListenable .
You can listen to the following SharedLockEventMap of all ISharedLock instances created by the ISharedLockProvider.
To understand how this method works, refer to IEventListenable .
You can listen to the following SharedLockEventMap of all ISharedLock instances created by the ISharedLockProvider.
To understand how this method works, refer to IEventListenable .
SharedLockProviderclass can be derived from anyISharedLockAdapterorIDatabaseSharedLockAdapter.Note the
ISharedLockinstances created by theSharedLockProviderclass 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/shared-lock"