-
Notifications
You must be signed in to change notification settings - Fork 727
Don't immediately return promise within newly created promise #807
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 all 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 |
|---|---|---|
|
|
@@ -161,21 +161,15 @@ export interface LaunchResult { | |
|
|
||
| export function launchOmniSharp(details: LaunchDetails): Promise<LaunchResult> { | ||
| return new Promise<LaunchResult>((resolve, reject) => { | ||
| try { | ||
| return launch(details).then(result => { | ||
| // async error - when target not not ENEOT | ||
| result.process.on('error', reject); | ||
|
|
||
| // success after a short freeing event loop | ||
| setTimeout(function () { | ||
| resolve(result); | ||
| }, 0); | ||
| }, err => { | ||
| reject(err); | ||
| }); | ||
| } catch (err) { | ||
| reject(err); | ||
| } | ||
| launch(details).then(result => { | ||
| // async error - when target not not ENEOT | ||
| result.process.on('error', reject); | ||
|
|
||
| // success after a short freeing event loop | ||
| setTimeout(function () { | ||
| resolve(result); | ||
| }, 0); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -189,34 +183,31 @@ function launch(details: LaunchDetails): Promise<LaunchResult> { | |
| } | ||
|
|
||
| function launchWindows(details: LaunchDetails): Promise<LaunchResult> { | ||
| return new Promise<LaunchResult>(resolve => { | ||
|
|
||
| function escapeIfNeeded(arg: string) { | ||
| const hasSpaceWithoutQuotes = /^[^"].* .*[^"]/; | ||
| return hasSpaceWithoutQuotes.test(arg) | ||
| ? `"${arg}"` | ||
| : arg; | ||
| } | ||
| function escapeIfNeeded(arg: string) { | ||
| const hasSpaceWithoutQuotes = /^[^"].* .*[^"]/; | ||
| return hasSpaceWithoutQuotes.test(arg) | ||
| ? `"${arg}"` | ||
| : arg; | ||
| } | ||
|
|
||
| let args = details.args.slice(0); // create copy of details.args | ||
| args.unshift(details.serverPath); | ||
| args = [[ | ||
| '/s', | ||
| '/c', | ||
| '"' + args.map(escapeIfNeeded).join(' ') + '"' | ||
| ].join(' ')]; | ||
|
|
||
| let process = spawn('cmd', args, <any>{ | ||
| windowsVerbatimArguments: true, | ||
| detached: false, | ||
| cwd: details.cwd | ||
| }); | ||
| let args = details.args.slice(0); // create copy of details.args | ||
| args.unshift(details.serverPath); | ||
| args = [[ | ||
| '/s', | ||
| '/c', | ||
| '"' + args.map(escapeIfNeeded).join(' ') + '"' | ||
| ].join(' ')]; | ||
|
|
||
| let process = spawn('cmd', args, <any>{ | ||
| windowsVerbatimArguments: true, | ||
| detached: false, | ||
| cwd: details.cwd | ||
| }); | ||
|
|
||
| return resolve({ | ||
| process, | ||
| command: details.serverPath, | ||
| usingMono: false | ||
| }); | ||
| return Promise.resolve({ | ||
| process, | ||
| command: details.serverPath, | ||
| usingMono: false | ||
| }); | ||
|
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. Why not putting all the code in a Promise like previously?
Member
Author
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. Any exceptions should ultimately be propagated to the caller in server.ts. The |
||
| } | ||
|
|
||
|
|
@@ -233,48 +224,44 @@ function launchNix(details: LaunchDetails): Promise<LaunchResult> { | |
| } | ||
|
|
||
| function launchNixCoreCLR(details: LaunchDetails): Promise<LaunchResult> { | ||
| return new Promise<LaunchResult>(resolve => { | ||
| let process = spawn(details.serverPath, details.args, { | ||
| detached: false, | ||
| cwd: details.cwd | ||
| }); | ||
| let process = spawn(details.serverPath, details.args, { | ||
| detached: false, | ||
| cwd: details.cwd | ||
| }); | ||
|
|
||
| return resolve({ | ||
| process, | ||
| command: details.serverPath, | ||
| usingMono: false | ||
| }); | ||
| return Promise.resolve({ | ||
| process, | ||
| command: details.serverPath, | ||
| usingMono: false | ||
| }); | ||
| } | ||
|
|
||
| function launchNixMono(details: LaunchDetails): Promise<LaunchResult> { | ||
| return new Promise<LaunchResult>((resolve, reject) => { | ||
| return canLaunchMono().then(() => { | ||
| let args = details.args.slice(0); // create copy of details.args | ||
| args.unshift(details.serverPath); | ||
|
|
||
| let process = spawn('mono', args, { | ||
| detached: false, | ||
| cwd: details.cwd | ||
| }); | ||
| return canLaunchMono().then(() => { | ||
| let args = details.args.slice(0); // create copy of details.args | ||
| args.unshift(details.serverPath); | ||
|
|
||
| return resolve({ | ||
| process, | ||
| command: details.serverPath, | ||
| usingMono: true | ||
| }); | ||
| let process = spawn('mono', args, { | ||
| detached: false, | ||
| cwd: details.cwd | ||
| }); | ||
|
|
||
| return { | ||
| process, | ||
| command: details.serverPath, | ||
| usingMono: true | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| function canLaunchMono(): Promise<void> { | ||
| return new Promise<void>((resolve, reject) => { | ||
| hasMono('>=4.0.1').then(success => { | ||
| if (success) { | ||
| return resolve(); | ||
| resolve(); | ||
| } | ||
| else { | ||
| return reject(new Error('Cannot start Omnisharp because Mono version >=4.0.1 is required.')); | ||
| reject(new Error('Cannot start Omnisharp because Mono version >=4.0.1 is required.')); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
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.
Is it normal that rejection of launch promise is not handled here?
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.
It's intended that rejection will be propagated to the caller, which is in server.ts here.
Uh oh!
There was an error while loading. Please reload this page.
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.
If there is no reject callback AND the "launch" promise is not returned anywhere, I'm quite sure that the error will be silent.
This should be the correct way to bubble the error to the caller: