haixunMaster/lib/threads-browser/session-lock.ts

11 lines
312 B
TypeScript
Raw Normal View History

2026-06-21 12:50:31 +00:00
let chain: Promise<void> = Promise.resolve();
/** 序列化 Threads 瀏覽器操作,避免同時開多個 profile 實例。 */
export function withSessionLock<T>(fn: () => Promise<T>): Promise<T> {
const run = chain.then(fn);
chain = run.then(
() => undefined,
() => undefined
);
return run;
}