aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/xtext/UpdateService.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-26 17:19:36 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-26 17:45:20 +0200
commitd510b07aededd59443e877c4e7c7b6e2b9822dfe (patch)
tree64e4675ac200d4d85f5818472acd908666758969 /subprojects/frontend/src/xtext/UpdateService.ts
parentrefactor(frontend): simplify UpdateService further (diff)
downloadrefinery-d510b07aededd59443e877c4e7c7b6e2b9822dfe.tar.gz
refinery-d510b07aededd59443e877c4e7c7b6e2b9822dfe.tar.zst
refinery-d510b07aededd59443e877c4e7c7b6e2b9822dfe.zip
refactor(frontend): custom mutex implementation
Lets us track priorities of tasks without cancellation.
Diffstat (limited to 'subprojects/frontend/src/xtext/UpdateService.ts')
-rw-r--r--subprojects/frontend/src/xtext/UpdateService.ts23
1 files changed, 13 insertions, 10 deletions
diff --git a/subprojects/frontend/src/xtext/UpdateService.ts b/subprojects/frontend/src/xtext/UpdateService.ts
index d8782d90..f1abce52 100644
--- a/subprojects/frontend/src/xtext/UpdateService.ts
+++ b/subprojects/frontend/src/xtext/UpdateService.ts
@@ -1,9 +1,10 @@
1import type { ChangeDesc, Transaction } from '@codemirror/state'; 1import type { ChangeDesc, Transaction } from '@codemirror/state';
2import { E_CANCELED, E_TIMEOUT } from 'async-mutex';
3import { debounce } from 'lodash-es'; 2import { debounce } from 'lodash-es';
4import { nanoid } from 'nanoid'; 3import { nanoid } from 'nanoid';
5 4
6import type EditorStore from '../editor/EditorStore'; 5import type EditorStore from '../editor/EditorStore';
6import CancelledError from '../utils/CancelledError';
7import TimeoutError from '../utils/TimeoutError';
7import getLogger from '../utils/getLogger'; 8import getLogger from '../utils/getLogger';
8 9
9import UpdateStateTracker from './UpdateStateTracker'; 10import UpdateStateTracker from './UpdateStateTracker';
@@ -66,7 +67,7 @@ export default class UpdateService {
66 this.updateFullTextOrThrow().catch((error) => { 67 this.updateFullTextOrThrow().catch((error) => {
67 // Let E_TIMEOUT errors propagate, since if the first update times out, 68 // Let E_TIMEOUT errors propagate, since if the first update times out,
68 // we can't use the connection. 69 // we can't use the connection.
69 if (error === E_CANCELED) { 70 if (error instanceof CancelledError) {
70 // Content assist will perform a full-text update anyways. 71 // Content assist will perform a full-text update anyways.
71 log.debug('Full text update cancelled'); 72 log.debug('Full text update cancelled');
72 return; 73 return;
@@ -87,7 +88,7 @@ export default class UpdateService {
87 } 88 }
88 if (!this.tracker.lockedForUpdate) { 89 if (!this.tracker.lockedForUpdate) {
89 this.updateOrThrow().catch((error) => { 90 this.updateOrThrow().catch((error) => {
90 if (error === E_CANCELED || error === E_TIMEOUT) { 91 if (error instanceof CancelledError || error instanceof TimeoutError) {
91 log.debug('Idle update cancelled'); 92 log.debug('Idle update cancelled');
92 return; 93 return;
93 } 94 }
@@ -163,11 +164,15 @@ export default class UpdateService {
163 return this.fetchContentAssistFetchOnly(params, this.xtextStateId); 164 return this.fetchContentAssistFetchOnly(params, this.xtextStateId);
164 } 165 }
165 try { 166 try {
166 return await this.tracker.runExclusiveHighPriority(() => 167 return await this.tracker.runExclusive(
167 this.fetchContentAssistExclusive(params, signal), 168 () => this.fetchContentAssistExclusive(params, signal),
169 true,
168 ); 170 );
169 } catch (error) { 171 } catch (error) {
170 if ((error === E_CANCELED || error === E_TIMEOUT) && signal.aborted) { 172 if (
173 (error instanceof CancelledError || error instanceof TimeoutError) &&
174 signal.aborted
175 ) {
171 return []; 176 return [];
172 } 177 }
173 throw error; 178 throw error;
@@ -261,9 +266,7 @@ export default class UpdateService {
261 } 266 }
262 267
263 formatText(): Promise<void> { 268 formatText(): Promise<void> {
264 return this.tracker.runExclusiveWithRetries(() => 269 return this.tracker.runExclusive(() => this.formatTextExclusive());
265 this.formatTextExclusive(),
266 );
267 } 270 }
268 271
269 private async formatTextExclusive(): Promise<void> { 272 private async formatTextExclusive(): Promise<void> {
@@ -294,7 +297,7 @@ export default class UpdateService {
294 try { 297 try {
295 await this.updateOrThrow(); 298 await this.updateOrThrow();
296 } catch (error) { 299 } catch (error) {
297 if (error === E_CANCELED || error === E_TIMEOUT) { 300 if (error instanceof CancelledError || error instanceof TimeoutError) {
298 return { cancelled: true }; 301 return { cancelled: true };
299 } 302 }
300 throw error; 303 throw error;