fix: 尝试修复同实例多窗口时点击超时,修复 Gemini 无法选择模型 (ref #30, ref #31)

This commit is contained in:
foxhui
2026-03-25 16:19:38 +08:00
Unverified
parent 2029ef345e
commit c234943fc2
5 changed files with 62 additions and 9 deletions
+34
View File
@@ -0,0 +1,34 @@
/**
* @fileoverview 轻量异步互斥锁
* @description 保证同一时刻只有一个 async 任务持有锁,用于防止同一浏览器实例的多个 Worker 并发操作鼠标。
*/
export class AsyncMutex {
constructor() {
this._queue = [];
this._locked = false;
}
/**
* 获取锁,返回释放函数
* @returns {Promise<() => void>}
*/
acquire() {
return new Promise(resolve => {
const tryAcquire = () => {
if (!this._locked) {
this._locked = true;
resolve(() => {
this._locked = false;
if (this._queue.length > 0) {
this._queue.shift()();
}
});
} else {
this._queue.push(tryAcquire);
}
};
tryAcquire();
});
}
}