feat: switch to config file system
This commit is contained in:
parent
5be3cb345e
commit
76d263b7e6
28 changed files with 1071 additions and 883 deletions
32
app/utils/mutex.ts
Normal file
32
app/utils/mutex.ts
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue