diff options
author | 2022-08-26 17:19:36 +0200 | |
---|---|---|
committer | 2022-08-26 17:45:20 +0200 | |
commit | d510b07aededd59443e877c4e7c7b6e2b9822dfe (patch) | |
tree | 64e4675ac200d4d85f5818472acd908666758969 /subprojects/frontend/src/utils/PendingTask.ts | |
parent | refactor(frontend): simplify UpdateService further (diff) | |
download | refinery-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/utils/PendingTask.ts')
-rw-r--r-- | subprojects/frontend/src/utils/PendingTask.ts | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/subprojects/frontend/src/utils/PendingTask.ts b/subprojects/frontend/src/utils/PendingTask.ts index 205c8452..d0b24c1f 100644 --- a/subprojects/frontend/src/utils/PendingTask.ts +++ b/subprojects/frontend/src/utils/PendingTask.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import TimeoutError from './TimeoutError'; | ||
1 | import getLogger from './getLogger'; | 2 | import getLogger from './getLogger'; |
2 | 3 | ||
3 | const log = getLogger('utils.PendingTask'); | 4 | const log = getLogger('utils.PendingTask'); |
@@ -15,16 +16,14 @@ export default class PendingTask<T> { | |||
15 | resolveCallback: (value: T) => void, | 16 | resolveCallback: (value: T) => void, |
16 | rejectCallback: (reason?: unknown) => void, | 17 | rejectCallback: (reason?: unknown) => void, |
17 | timeoutMs: number | undefined, | 18 | timeoutMs: number | undefined, |
18 | timeoutCallback: () => void | undefined, | 19 | timeoutCallback?: (() => void) | undefined, |
19 | ) { | 20 | ) { |
20 | this.resolveCallback = resolveCallback; | 21 | this.resolveCallback = resolveCallback; |
21 | this.rejectCallback = rejectCallback; | 22 | this.rejectCallback = rejectCallback; |
22 | this.timeout = setTimeout(() => { | 23 | this.timeout = setTimeout(() => { |
23 | if (!this.resolved) { | 24 | if (!this.resolved) { |
24 | this.reject(new Error('Request timed out')); | 25 | this.reject(new TimeoutError()); |
25 | if (timeoutCallback) { | 26 | timeoutCallback?.(); |
26 | timeoutCallback(); | ||
27 | } | ||
28 | } | 27 | } |
29 | }, timeoutMs); | 28 | }, timeoutMs); |
30 | } | 29 | } |