From d3cf2e18757d22e549d2e4cf7b619938098d44d4 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 27 Aug 2024 12:51:06 -0400 Subject: [PATCH 1/4] fix: go back to 10s wait before showing "keep waiting" message --- src/net-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net-utils.ts b/src/net-utils.ts index 723c874..5171498 100644 --- a/src/net-utils.ts +++ b/src/net-utils.ts @@ -69,7 +69,7 @@ export async function openBrowserWhenReady( }, async () => { const portsOpen = [port, ...additionalPorts].map((p) => - retryUntilTimeout(20000, () => isPortOpen("127.0.0.1", p)) + retryUntilTimeout(10000, () => isPortOpen("127.0.0.1", p)) ); const portsOpenPromise = Promise.all(portsOpen); From 5db20b9198fad169da3b0195bdb3ee7eb3814a38 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 27 Aug 2024 12:51:12 -0400 Subject: [PATCH 2/4] chore: style --- src/net-utils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/net-utils.ts b/src/net-utils.ts index 5171498..6309b37 100644 --- a/src/net-utils.ts +++ b/src/net-utils.ts @@ -39,7 +39,9 @@ async function isPortOpen( }); } -async function getTerminalClosedPromise(terminal: vscode.Terminal): Promise { +async function getTerminalClosedPromise( + terminal: vscode.Terminal +): Promise { return new Promise((resolve) => { vscode.window.onDidCloseTerminal((term) => { if (term === terminal) { @@ -76,7 +78,10 @@ export async function openBrowserWhenReady( if (!terminal) { return portsOpenPromise; } else { - return Promise.race([portsOpenPromise, getTerminalClosedPromise(terminal)]); + return Promise.race([ + portsOpenPromise, + getTerminalClosedPromise(terminal), + ]); } } ); From aa79045990fc73cbbb8240c811136e25583a3761 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 27 Aug 2024 13:20:40 -0400 Subject: [PATCH 3/4] feat: wait longer if user wants to keep waiting --- src/net-utils.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/net-utils.ts b/src/net-utils.ts index 6309b37..5bbc6f5 100644 --- a/src/net-utils.ts +++ b/src/net-utils.ts @@ -61,7 +61,8 @@ async function getTerminalClosedPromise( export async function openBrowserWhenReady( port: number, additionalPorts: number[] = [], - terminal?: vscode.Terminal + terminal?: vscode.Terminal, + timeout: number = 10000 ): Promise { const portsOpenResult = await vscode.window.withProgress( { @@ -71,7 +72,7 @@ export async function openBrowserWhenReady( }, async () => { const portsOpen = [port, ...additionalPorts].map((p) => - retryUntilTimeout(10000, () => isPortOpen("127.0.0.1", p)) + retryUntilTimeout(timeout, () => isPortOpen("127.0.0.1", p)) ); const portsOpenPromise = Promise.all(portsOpen); @@ -92,8 +93,9 @@ export async function openBrowserWhenReady( } if (portsOpenResult.filter((p) => !p).length > 0) { + const timeoutStr = Math.floor(timeout / 1000); const action = await vscode.window.showErrorMessage( - "Shiny app took longer than 10s to start, not launching browser.", + `Shiny app took longer than ${timeoutStr}s to start, not launching browser.`, terminal ? "Show Shiny process" : "", "Keep waiting" ); @@ -104,7 +106,7 @@ export async function openBrowserWhenReady( ); return; } - return openBrowserWhenReady(port, additionalPorts, terminal); + return openBrowserWhenReady(port, additionalPorts, terminal, 30000); } if (action === "Show Shiny process") { terminal?.show(); From 7ea6565c71c21137f6bfc8749d8cd1a2eab00e19 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 27 Aug 2024 13:33:21 -0400 Subject: [PATCH 4/4] docs: document timeout param --- src/net-utils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/net-utils.ts b/src/net-utils.ts index 5bbc6f5..4a29f05 100644 --- a/src/net-utils.ts +++ b/src/net-utils.ts @@ -57,6 +57,10 @@ async function getTerminalClosedPromise( * @param port The port to open the browser for. * @param additionalPorts Additional ports to wait for before opening the * browser. + * @param timeout Milliseconds to wait for the port to open before letting the + * user know something is wrong and asking if they'd like to check on the Shiny + * process or keep waiting. We start with a low 10s wait because some apps might + * fail quickly, but we increase to 30s if the user chooses to keep waiting. */ export async function openBrowserWhenReady( port: number,