diff --git a/client/src/plugins/engine.js b/client/src/plugins/engine.js index 0b0f8d4..bdb6743 100644 --- a/client/src/plugins/engine.js +++ b/client/src/plugins/engine.js @@ -5,15 +5,36 @@ export default (context, inject) => { const engine = { lastFetched: [0, 0, 0, 0, 0], + isActive: false, + shouldStop: false, + async start() { if (!store.state.engine.user) { if (!await this.fetchUserInfo()) { window.location.href = "/" } } + if (this.isActive) { + console.warn('attempt to start already running engine!') + return + } + + this.isActive = true this.fetchUpdate() }, + + stop() { + if (!this.isActive) return + this.shouldStop = true + }, + async fetchUpdate() { + if (this.shouldStop || !this.isActive) { + this.isActive = false + this.shouldStop = false + return + } + let delay = 0 try { const url = buildUrl($config.serverBaseUrl, {