Skip to content

Commit

Permalink
Address review; fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
somebody1234 committed Dec 15, 2023
1 parent 7e14757 commit 2d2c9c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
11 changes: 5 additions & 6 deletions app/gui2/shared/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ export interface BackoffOptions<E> {
retryDelay?: number
retryDelayMultiplier?: number
retryDelayMax?: number
/**
* Called when the promise return an error result, and the next retry is about to be attempted.
* When this function returns `false`, the backoff is immediately aborted. When this function is
* not provided, the backoff will always continue until the maximum number of retries is reached.
*/
/** Called when the promise throws an error, and the next retry is about to be attempted.
* When this function returns `false`, the backoff is immediately aborted. When this function
* is not provided, the backoff will always continue until the maximum number of retries
* is reached. * */
onBeforeRetry?: (
error: E,
retryCount: number,
Expand All @@ -18,7 +17,7 @@ export interface BackoffOptions<E> {
) => boolean | void
/** Called right before returning. */
onSuccess?: (retryCount: number) => void
/** Called on the final retry, right before throwing an error.
/** Called after the final retry, right before throwing an error.
* Note that `onBeforeRetry` is *not* called on the final retry, as there is nothing after the
* final retry. */
onFailure?: (error: E, retryCount: number) => void
Expand Down
17 changes: 7 additions & 10 deletions app/gui2/ydoc-server/languageServerSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as random from 'lib0/random'
import * as Y from 'yjs'
import { LanguageServer, computeTextChecksum } from '../shared/languageServer'
import { Checksum, FileEdit, Path, response } from '../shared/languageServerTypes'
import { exponentialBackoff, exponentialBackoffMessages } from '../shared/retry'
import { exponentialBackoff, printingCallbacks } from '../shared/retry'
import {
DistributedProject,
ExprId,
Expand Down Expand Up @@ -111,10 +111,7 @@ export class LanguageServerSession {
if (fileInfo.attributes.kind.type == 'File') {
await exponentialBackoff(
() => this.getModuleModel(event.path).open(),
exponentialBackoffMessages(
`opened new file '${path}'`,
`open new file '${path}'`,
),
printingCallbacks(`opened new file '${path}'`, `open new file '${path}'`),
)
}
}
Expand All @@ -123,7 +120,7 @@ export class LanguageServerSession {
case 'Modified': {
await exponentialBackoff(
async () => this.tryGetExistingModuleModel(event.path)?.reload(),
exponentialBackoffMessages(`reloaded file '${path}'`, `reload file '${path}'`),
printingCallbacks(`reloaded file '${path}'`, `reload file '${path}'`),
)
break
}
Expand All @@ -137,21 +134,21 @@ export class LanguageServerSession {
try {
await exponentialBackoff(
async () => this.tryGetExistingModuleModel(event.path)?.reload(),
exponentialBackoffMessages(`reloaded file '${path}'`, `reload file '${path}'`),
printingCallbacks(`reloaded file '${path}'`, `reload file '${path}'`),
)
} catch {
this.restartClient()
}
})
exponentialBackoff(
() => this.readInitialState(),
exponentialBackoffMessages('read initial state', 'read initial state'),
printingCallbacks('read initial state', 'read initial state'),
).catch((error) => {
console.error('Could not read initial state.')
console.error(error)
exponentialBackoff(
async () => this.restartClient(),
exponentialBackoffMessages('restarted RPC client', 'restart RPC client'),
printingCallbacks('restarted RPC client', 'restart RPC client'),
)
})
return { client: this.client, ls: this.ls }
Expand Down Expand Up @@ -620,7 +617,7 @@ class ModulePersistence extends ObservableV2<{ removed: () => void }> {
}
return result
},
exponentialBackoffMessages(
printingCallbacks(
`opened file '${path}' for writing`,
`open file '${path}' for writing`,
),
Expand Down

0 comments on commit 2d2c9c9

Please sign in to comment.