diff options
author | 2021-10-26 21:40:36 +0200 | |
---|---|---|
committer | 2021-10-31 19:26:12 +0100 | |
commit | 232fbcafa863a3c28ab907b112c5257f0b6dc8f1 (patch) | |
tree | 20b0266e7d325e3c4ad6676616b35a7eb5f91fd8 /language-web/src/main/js/editor/PendingRequest.ts | |
parent | feat(web): show lint status on lint button (diff) | |
download | refinery-232fbcafa863a3c28ab907b112c5257f0b6dc8f1.tar.gz refinery-232fbcafa863a3c28ab907b112c5257f0b6dc8f1.tar.zst refinery-232fbcafa863a3c28ab907b112c5257f0b6dc8f1.zip |
chore(web): refactor websocket state machine
Diffstat (limited to 'language-web/src/main/js/editor/PendingRequest.ts')
-rw-r--r-- | language-web/src/main/js/editor/PendingRequest.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/language-web/src/main/js/editor/PendingRequest.ts b/language-web/src/main/js/editor/PendingRequest.ts index 784f06ec..49d4c36c 100644 --- a/language-web/src/main/js/editor/PendingRequest.ts +++ b/language-web/src/main/js/editor/PendingRequest.ts | |||
@@ -9,16 +9,24 @@ export class PendingRequest { | |||
9 | 9 | ||
10 | private readonly rejectCallback: (reason?: unknown) => void; | 10 | private readonly rejectCallback: (reason?: unknown) => void; |
11 | 11 | ||
12 | private readonly timeoutCallback: () => void; | ||
13 | |||
12 | private resolved = false; | 14 | private resolved = false; |
13 | 15 | ||
14 | private timeoutId: NodeJS.Timeout; | 16 | private timeoutId: NodeJS.Timeout; |
15 | 17 | ||
16 | constructor(resolve: (value: unknown) => void, reject: (reason?: unknown) => void) { | 18 | constructor( |
19 | resolve: (value: unknown) => void, | ||
20 | reject: (reason?: unknown) => void, | ||
21 | timeout: () => void, | ||
22 | ) { | ||
17 | this.resolveCallback = resolve; | 23 | this.resolveCallback = resolve; |
18 | this.rejectCallback = reject; | 24 | this.rejectCallback = reject; |
25 | this.timeoutCallback = timeout; | ||
19 | this.timeoutId = setTimeout(() => { | 26 | this.timeoutId = setTimeout(() => { |
20 | if (!this.resolved) { | 27 | if (!this.resolved) { |
21 | this.reject(new Error('Request timed out')); | 28 | this.reject(new Error('Request timed out')); |
29 | this.timeoutCallback(); | ||
22 | } | 30 | } |
23 | }, REQUEST_TIMEOUT_MS); | 31 | }, REQUEST_TIMEOUT_MS); |
24 | } | 32 | } |