mirror of
https://github.com/tale/headplane.git
synced 2026-08-22 10:46:38 +00:00
feat: switch to config file system
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
class Mutex {
|
||||
private locked = false;
|
||||
private queue: (() => void)[] = [];
|
||||
|
||||
constructor(locked: boolean) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
acquire() {
|
||||
return new Promise<void>((resolve) => {
|
||||
if (!this.locked) {
|
||||
this.locked = true;
|
||||
resolve();
|
||||
} else {
|
||||
this.queue.push(resolve);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
release() {
|
||||
if (this.queue.length > 0) {
|
||||
const next = this.queue.shift();
|
||||
next?.();
|
||||
} else {
|
||||
this.locked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default function mutex(locked = false) {
|
||||
return new Mutex(locked);
|
||||
}
|
||||
Reference in New Issue
Block a user