histoire
Version:
A fast story book powered by Vite
26 lines (25 loc) • 968 B
JavaScript
/** Builds an idempotent lease and reports any cleanup that cannot be confirmed. */
export function createCaptureBrowserLease(options) {
let releasing;
/** Shares one terminal outcome when release, discard, and owner close race. */
function finish(action) {
return releasing ??= (async () => {
try {
await action();
}
catch (error) {
throw options.retainCleanupFailure(error);
}
options.onReleased(release);
})();
}
/** Returns a confirmed healthy browser to its idle process pool. */
function release() {
return finish(options.releaseBrowser);
}
/** Destroys the exact process after context or browser API cleanup uncertainty. */
function discard() {
return finish(options.discardBrowser ?? options.releaseBrowser);
}
return { browser: options.browser, source: options.source, release, discard };
}