fix(tracker): cancel work if stopped during the /start request (no WebWorker errors blasting)

This commit is contained in:
Alex Kaminskii 2022-09-12 16:11:24 +02:00
parent 366a258b56
commit fcc7b27c61

View file

@ -213,9 +213,9 @@ export default class App {
}
}
safe<T extends (...args: any[]) => void>(fn: T): T {
safe<T extends (this: any, ...args: any[]) => void>(fn: T): T {
const app = this
return function (this: any, ...args: any) {
return function (this: any, ...args: any[]) {
try {
fn.apply(this, args)
} catch (e) {
@ -225,12 +225,10 @@ export default class App {
// message: e.message,
// stack: e.stack
}
} as any // TODO: correct typing
} as T // TODO: correct typing
}
attachCommitCallback(cb: CommitCallback): void {
// TODO!: what if start callback added when activityState === Active ?
// For example - attachEventListener() called during dynamic <iframe> appearance
this.commitCallbacks.push(cb)
}
attachStartCallback(cb: StartCallback, useSafe = false): void {
@ -245,6 +243,7 @@ export default class App {
}
this.stopCallbacks.push(cb)
}
// Use app.nodes.attachNodeListener for registered nodes instead
attachEventListener(
target: EventTarget,
type: string,
@ -424,6 +423,9 @@ export default class App {
if (!this.worker) {
return Promise.reject('no worker found after start request (this might not happen)')
}
if (this.activityState === ActivityState.NotActive) {
return Promise.reject('Tracker stopped during authorisation')
}
const {
token,
userUUID,