-
Notifications
You must be signed in to change notification settings - Fork 641
feat(amazonq): user cancellable lsp download #6573
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
07ec9b2
feat(amazonq): user cancellable lsp download
04c7a35
minor refactors
b4b6a05
let error propogate up and add call back feature to timeout
ecd939e
fix typo
d6f8e77
added test for waitUntil
fbc0de0
renamed to throwOnError
ee347a9
wrap request cancelled error in isUserCancelledError
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,11 +223,12 @@ interface WaitUntilOptions { | |
readonly backoff?: number | ||
/** | ||
* Only retries when an error is thrown, otherwise returning the immediate result. | ||
* Can also be a callback for conditional retry based on errors | ||
* - 'truthy' arg is ignored | ||
* - If the timeout is reached it throws the last error | ||
* - default: false | ||
*/ | ||
readonly retryOnFail?: boolean | ||
readonly retryOnFail?: boolean | ((error: Error) => boolean) | ||
} | ||
|
||
export const waitUntilDefaultTimeout = 2000 | ||
|
@@ -247,6 +248,11 @@ export async function waitUntil<T>( | |
fn: () => Promise<T>, | ||
options: WaitUntilOptions & { retryOnFail: false } | ||
): Promise<T | undefined> | ||
export async function waitUntil<T>( | ||
justinmk3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fn: () => Promise<T>, | ||
options: WaitUntilOptions & { retryOnFail: (error: Error) => boolean } | ||
): Promise<T> | ||
|
||
export async function waitUntil<T>( | ||
fn: () => Promise<T>, | ||
options: Omit<WaitUntilOptions, 'retryOnFail'> | ||
|
@@ -267,6 +273,17 @@ export async function waitUntil<T>(fn: () => Promise<T>, options: WaitUntilOptio | |
let elapsed: number = 0 | ||
let remaining = opt.timeout | ||
|
||
// Internal helper to determine if we should retry | ||
function shouldRetry(error: Error | undefined): boolean { | ||
if (error === undefined) { | ||
return typeof opt.retryOnFail === 'boolean' ? opt.retryOnFail : true | ||
} | ||
if (typeof opt.retryOnFail === 'function') { | ||
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. Can we make it always be a function? That should simplify some logic, eliminate an overload, and eliminate some tests. It's trivial for calls to pass |
||
return opt.retryOnFail(error) | ||
} | ||
return opt.retryOnFail | ||
} | ||
|
||
for (let i = 0; true; i++) { | ||
const start: number = globals.clock.Date.now() | ||
let result: T | ||
|
@@ -279,16 +296,16 @@ export async function waitUntil<T>(fn: () => Promise<T>, options: WaitUntilOptio | |
result = await fn() | ||
} | ||
|
||
if (opt.retryOnFail || (opt.truthy && result) || (!opt.truthy && result !== undefined)) { | ||
if (shouldRetry(lastError) || (opt.truthy && result) || (!opt.truthy && result !== undefined)) { | ||
return result | ||
} | ||
} catch (e) { | ||
if (!opt.retryOnFail) { | ||
// Unlikely to hit this, but exists for typing | ||
if (!(e instanceof Error)) { | ||
throw e | ||
} | ||
|
||
// Unlikely to hit this, but exists for typing | ||
if (!(e instanceof Error)) { | ||
if (!shouldRetry(e)) { | ||
throw e | ||
} | ||
|
||
|
@@ -300,10 +317,9 @@ export async function waitUntil<T>(fn: () => Promise<T>, options: WaitUntilOptio | |
|
||
// If the sleep will exceed the timeout, abort early | ||
if (elapsed + interval >= remaining) { | ||
if (!opt.retryOnFail) { | ||
if (!shouldRetry(lastError)) { | ||
return undefined | ||
} | ||
|
||
throw lastError | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.