Skip to content

Commit

Permalink
fix notebook restart always timing out
Browse files Browse the repository at this point in the history
  • Loading branch information
seeM committed Nov 22, 2024
1 parent fd16b3a commit 36827f0
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ export class NotebookSessionService implements vscode.Disposable {
}
}

// Create a promise that resolves when the session is ready.
const promise = new Promise<void>((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}`);
Expand All @@ -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<void>((_, reject) =>
setTimeout(() => reject(new Error('Timeout waiting for runtime to restart')), 5000));
const promise = new Promise<void>((resolve) => {
const disposable = session.onDidChangeRuntimeState((state) => {
if (state === positron.RuntimeState.Ready) {
disposable.dispose();
resolve();
}
});
});
try {
await Promise.race([promise, timeout]);
} catch (err) {
Expand Down

0 comments on commit 36827f0

Please sign in to comment.