|
1 | 1 | import * as fs from 'fs'; |
2 | 2 | import * as path from 'path'; |
3 | 3 | import { promisify } from 'util'; |
4 | | -import { Mutex } from 'async-mutex'; |
5 | 4 |
|
6 | 5 | 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'; |
8 | 7 |
|
9 | 8 | import { reportError } from './error-tracking'; |
10 | 9 | import { readFile, statFile, deleteFile } from './util'; |
@@ -51,14 +50,23 @@ export async function checkBrowserConfig(configPath: string) { |
51 | 50 | }) |
52 | 51 | } |
53 | 52 |
|
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; |
57 | 54 |
|
58 | 55 | 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; |
62 | 70 | } |
63 | 71 |
|
64 | 72 | export const getAvailableBrowsers = async (configPath: string) => { |
|
0 commit comments