bentocache
Version:
Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers
32 lines (31 loc) • 765 B
JavaScript
// src/cache/locks.ts
import { is } from "@julr/utils/is";
import { Mutex, withTimeout } from "async-mutex";
var Locks = class {
/**
* A map that will hold active locks for each key
*/
/**
* For a given key, get or create a new lock
*
* @param key Key to get or create a lock for
* @param timeout Time to wait to acquire the lock
*/
getOrCreateForKey(key, timeout) {
let lock = this.
if (!lock) {
lock = new Mutex();
this.
}
return is.number(timeout) ? withTimeout(lock, timeout) : lock;
}
release(key, releaser) {
releaser();
this.
}
};
export {
Locks
};
//# sourceMappingURL=chunk-TLJ7G3ZX.js.map