From 36827f05405977d05c62b8455f0f5ce8eb58dc41 Mon Sep 17 00:00:00 2001 From: seem Date: Fri, 22 Nov 2024 17:26:07 +0200 Subject: [PATCH] fix notebook restart always timing out --- .../src/notebookSessionService.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/extensions/positron-notebook-controllers/src/notebookSessionService.ts b/extensions/positron-notebook-controllers/src/notebookSessionService.ts index 8b122aa6ab7b..c1135e9ad3f7 100644 --- a/extensions/positron-notebook-controllers/src/notebookSessionService.ts +++ b/extensions/positron-notebook-controllers/src/notebookSessionService.ts @@ -350,6 +350,16 @@ export class NotebookSessionService implements vscode.Disposable { } } + // Create a promise that resolves when the session is ready. + const promise = new Promise((resolve) => { + const disposable = session.onDidChangeRuntimeState((state) => { + if (state === positron.RuntimeState.Ready) { + disposable.dispose(); + resolve(); + } + }); + }); + // Start the restart sequence. try { log.info(`Restarting session ${session.metadata.sessionId} for notebook ${notebookUri.path}`); @@ -362,14 +372,6 @@ export class NotebookSessionService implements vscode.Disposable { // Wait for the session to be ready, or for a timeout. const timeout = new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout waiting for runtime to restart')), 5000)); - const promise = new Promise((resolve) => { - const disposable = session.onDidChangeRuntimeState((state) => { - if (state === positron.RuntimeState.Ready) { - disposable.dispose(); - resolve(); - } - }); - }); try { await Promise.race([promise, timeout]); } catch (err) {