A threaded lock for Javascript written in Typescript
npm install threaded-lockA Promise based locking system that works between tabs (across multiple threads).
``
import ThreadedLock from "threaded-lock";
async function doStuff() {
// First, create a new lock
const tl = new ThreadedLock("cool-lock");
await tl.lock();
// Do some thread safe stuff in any tab
writeCookie();
waitOnAPICall();
// Unlock so other tabs can continue.
tl.unlock();
}
`
In another tab
`
import ThreadedLock from "threaded-lock";
async function doOtherStuff() {
// First, create a new lock
const tl = new ThreadedLock("cool-lock");
await tl.lock();
readUpdatedCookie();
// Unlock so other tabs can continue.
tl.unlock();
}
``