aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/ctx.ts
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-30 21:53:21 +0000
committerAleksey Kladov <[email protected]>2019-12-30 21:53:21 +0000
commitcdd7118cbf23e21c376092b3b2734407004b8dbf (patch)
treebf53aac74110d30eba6da346e764e003ffd8b9c4 /editors/code/src/ctx.ts
parent23bac120625ca96402426e241c91ed5f3d7ccc02 (diff)
Don't request inline hints repeatedly
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r--editors/code/src/ctx.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 75b3542f4..d3ef27e43 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -62,20 +62,23 @@ export class Ctx {
62 this.extCtx.subscriptions.push(d); 62 this.extCtx.subscriptions.push(d);
63 } 63 }
64 64
65 async sendRequestWithRetry<R>(method: string, param: any): Promise<R> { 65 async sendRequestWithRetry<R>(method: string, param: any, token: vscode.CancellationToken): Promise<R> {
66 await this.client.onReady(); 66 await this.client.onReady();
67 const nRetries = 3; 67 for (const delay of [2, 4, 6, 8, 10, null]) {
68 for (let triesLeft = nRetries; ; triesLeft--) {
69 try { 68 try {
70 return await this.client.sendRequest(method, param); 69 return await this.client.sendRequest(method, param, token);
71 } catch (e) { 70 } catch (e) {
72 if (e.code === lc.ErrorCodes.ContentModified && triesLeft > 0) { 71 if (e.code === lc.ErrorCodes.ContentModified && delay !== null) {
72 await sleep(10 * (1 << delay))
73 continue; 73 continue;
74 } 74 }
75 throw e; 75 throw e;
76 } 76 }
77 } 77 }
78 throw 'unreachable'
78 } 79 }
79} 80}
80 81
81export type Cmd = (...args: any[]) => any; 82export type Cmd = (...args: any[]) => any;
83
84const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))