diff options
author | 2021-10-27 21:35:57 +0200 | |
---|---|---|
committer | 2021-10-31 19:26:13 +0100 | |
commit | 2c94b73460452d55a4d0a5542509d1de1d9c071b (patch) | |
tree | fc25067e91109378ce4f09c66e7a9d5f6dba010c /language-web/src/main/js/editor/XtextWebSocketClient.ts | |
parent | chore(web): simplify websocket state machine (diff) | |
download | refinery-2c94b73460452d55a4d0a5542509d1de1d9c071b.tar.gz refinery-2c94b73460452d55a4d0a5542509d1de1d9c071b.tar.zst refinery-2c94b73460452d55a4d0a5542509d1de1d9c071b.zip |
chore(web): refactor PendingTask
Diffstat (limited to 'language-web/src/main/js/editor/XtextWebSocketClient.ts')
-rw-r--r-- | language-web/src/main/js/editor/XtextWebSocketClient.ts | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/language-web/src/main/js/editor/XtextWebSocketClient.ts b/language-web/src/main/js/editor/XtextWebSocketClient.ts index 489ac03d..5b775500 100644 --- a/language-web/src/main/js/editor/XtextWebSocketClient.ts +++ b/language-web/src/main/js/editor/XtextWebSocketClient.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { nanoid } from 'nanoid'; | 1 | import { nanoid } from 'nanoid'; |
2 | 2 | ||
3 | import { getLogger } from '../logging'; | 3 | import { getLogger } from '../logging'; |
4 | import { PendingRequest } from './PendingRequest'; | 4 | import { PendingTask } from '../utils/PendingTask'; |
5 | import { Timer } from '../utils/Timer'; | 5 | import { Timer } from '../utils/Timer'; |
6 | import { | 6 | import { |
7 | isErrorResponse, | 7 | isErrorResponse, |
@@ -23,6 +23,8 @@ const BACKGROUND_IDLE_TIMEOUT_MS = 5 * 60 * 1000; | |||
23 | 23 | ||
24 | const PING_TIMEOUT_MS = 10 * 1000; | 24 | const PING_TIMEOUT_MS = 10 * 1000; |
25 | 25 | ||
26 | const REQUEST_TIMEOUT_MS = 1000; | ||
27 | |||
26 | const log = getLogger('XtextWebSocketClient'); | 28 | const log = getLogger('XtextWebSocketClient'); |
27 | 29 | ||
28 | type ReconnectHandler = () => Promise<void>; | 30 | type ReconnectHandler = () => Promise<void>; |
@@ -49,7 +51,7 @@ export class XtextWebSocketClient { | |||
49 | 51 | ||
50 | connection!: WebSocket; | 52 | connection!: WebSocket; |
51 | 53 | ||
52 | pendingRequests = new Map<string, PendingRequest>(); | 54 | pendingRequests = new Map<string, PendingTask<unknown>>(); |
53 | 55 | ||
54 | onReconnect: ReconnectHandler; | 56 | onReconnect: ReconnectHandler; |
55 | 57 | ||
@@ -223,14 +225,14 @@ export class XtextWebSocketClient { | |||
223 | id: messageId, | 225 | id: messageId, |
224 | request, | 226 | request, |
225 | } as IXtextWebRequest); | 227 | } as IXtextWebRequest); |
226 | const promise = new Promise((resolve, reject) => { | 228 | log.trace('Sending message', message); |
227 | this.pendingRequests.set(messageId, new PendingRequest(resolve, reject, () => { | 229 | return new Promise((resolve, reject) => { |
230 | const task = new PendingTask(resolve, reject, REQUEST_TIMEOUT_MS, () => { | ||
228 | this.removePendingRequest(messageId); | 231 | this.removePendingRequest(messageId); |
229 | })); | 232 | }); |
233 | this.pendingRequests.set(messageId, task); | ||
234 | this.connection.send(message); | ||
230 | }); | 235 | }); |
231 | log.trace('Sending message', message); | ||
232 | this.connection.send(message); | ||
233 | return promise; | ||
234 | } | 236 | } |
235 | 237 | ||
236 | private handleMessage(messageStr: unknown) { | 238 | private handleMessage(messageStr: unknown) { |