-
Notifications
You must be signed in to change notification settings - Fork 510
Clean up WaitForSessionFile logic and support increasing timeout with warning #2653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,20 +174,36 @@ export class PowerShellProcess { | |
return true; | ||
} | ||
|
||
private waitForSessionFile(): Promise<utils.IEditorServicesSessionDetails> { | ||
return new Promise((resolve, reject) => { | ||
utils.waitForSessionFile(this.sessionFilePath, (sessionDetails, error) => { | ||
utils.deleteSessionFile(this.sessionFilePath); | ||
private sleep(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
private async waitForSessionFile(): Promise<utils.IEditorServicesSessionDetails> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! We've been using async/await in our Electron/Angular app code base and vastly prefer it to dealing with Promises directly. :-) |
||
const numOfTries = this.sessionSettings.developer.waitForSessionFileNumOfTries; | ||
|
||
if (error) { | ||
this.log.write(`Error occurred retrieving session file:\n${error}`); | ||
return reject(error); | ||
} | ||
// This is used to warn the user that the extension is taking longer than expected to startup. | ||
const warnUserThreshold = numOfTries / 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the warning, I'd imagine our standard expectation for startup time is a constant, like 30 seconds, rather than parameterised by the setting |
||
|
||
for (let i = numOfTries; i > 0; i--) { | ||
if (utils.checkIfFileExists(this.sessionFilePath)) { | ||
this.log.write("Session file found"); | ||
resolve(sessionDetails); | ||
}); | ||
}); | ||
const sessionDetails = utils.readSessionFile(this.sessionFilePath); | ||
utils.deleteSessionFile(this.sessionFilePath); | ||
return sessionDetails; | ||
} | ||
|
||
if (warnUserThreshold === i) { | ||
vscode.window.showWarningMessage(`Loading the PowerShell extension is taking longer than expected. | ||
If you're using anti-virus software, this can affect start up performance.`); | ||
} | ||
|
||
// Wait a bit and try again | ||
await this.sleep(2000); | ||
} | ||
|
||
const err = "Timed out waiting for session file to appear."; | ||
this.log.write(err); | ||
throw new Error(err); | ||
} | ||
|
||
private onTerminalClose(terminal: vscode.Terminal) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a setting I think it would make more sense to expose a timeout and then in the implementation just retry until the total exceeds the timeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that. Perhaps
powershell.developer.sessionStartupTimeout
?