mirror of
https://github.com/jo-inc/camofox-browser.git
synced 2026-10-02 04:14:41 +08:00
Standalone library modules from PR #62: - lib/persistence.js: atomic storageState save/restore with SHA256-hashed user dirs - lib/inflight.js: coalesceInflight primitive for concurrent session creation dedup - lib/cookies.js: importBootstrapCookies helper for first-run cookie seeding - Unit tests for all three modules Co-authored-by: company8 <compan@post.com>
17 lines
321 B
JavaScript
17 lines
321 B
JavaScript
async function coalesceInflight(map, key, factory) {
|
|
const existing = map.get(key);
|
|
if (existing) return existing;
|
|
|
|
const promise = (async () => {
|
|
try {
|
|
return await factory();
|
|
} finally {
|
|
map.delete(key);
|
|
}
|
|
})();
|
|
map.set(key, promise);
|
|
return promise;
|
|
}
|
|
|
|
export { coalesceInflight };
|