Skip to content

Commit 3726375

Browse files
committed
Batch queries for installed browsers
1 parent 599e2cf commit 3726375

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/browsers.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import { promisify } from 'util';
4-
import { Mutex } from 'async-mutex';
54

65
import * as getBrowserLauncherCb from '@httptoolkit/browser-launcher';
7-
import { LaunchOptions, BrowserInstance, Browser } from '@httptoolkit/browser-launcher';
6+
import { LaunchOptions, Launch, BrowserInstance, Browser } from '@httptoolkit/browser-launcher';
87

98
import { reportError } from './error-tracking';
109
import { readFile, statFile, deleteFile } from './util';
@@ -51,14 +50,23 @@ export async function checkBrowserConfig(configPath: string) {
5150
})
5251
}
5352

54-
// It's not safe to call getBrowserLauncher in parallel, as config files can
55-
// get corrupted. We use a mutex to serialize it.
56-
const getLauncherMutex = new Mutex();
53+
let launcher: Promise<Launch> | undefined;
5754

5855
function getLauncher(configPath: string) {
59-
return getLauncherMutex.runExclusive(() =>
60-
getBrowserLauncher(browserConfigPath(configPath))
61-
);
56+
if (!launcher) {
57+
const start = Date.now();
58+
console.log('Getting launcher...');
59+
launcher = getBrowserLauncher(browserConfigPath(configPath));
60+
launcher.then(() => console.log(`Got launcher, took ${Date.now() - start}ms`));
61+
62+
// Reset & retry if this fails somehow:
63+
launcher.catch((e) => {
64+
reportError(e);
65+
launcher = undefined;
66+
});
67+
}
68+
69+
return launcher;
6270
}
6371

6472
export const getAvailableBrowsers = async (configPath: string) => {

0 commit comments

Comments
 (0)