diff options
author | dartcafe <github@dartcafe.de> | 2021-02-27 10:43:41 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2021-02-27 10:43:41 +0300 |
commit | cc2065aa69630cba75793e4b55544ed41ca33e99 (patch) | |
tree | 0e5d863eec22c124c18cae76a332193ab43ef9d3 /src/js/views | |
parent | 2c68439975374dcd2d6c90a56818fa1b861ad6f1 (diff) |
promise.all for async loadings
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src/js/views')
-rw-r--r-- | src/js/views/Vote.vue | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/js/views/Vote.vue b/src/js/views/Vote.vue index 4aabcb51..0be1e2ae 100644 --- a/src/js/views/Vote.vue +++ b/src/js/views/Vote.vue @@ -374,33 +374,53 @@ export default { params: { offset: this.lastUpdated }, cancelToken: this.cancelToken.token, }) + const dispatches = [] + console.debug('polls', 'update detected', response.data.updates) + response.data.updates.forEach((item) => { this.lastUpdated = (item.updated > this.lastUpdated) ? item.updated : this.lastUpdated if (item.table === 'polls') { - this.$store.dispatch('poll/get') + dispatches.push('poll/get') + // this.$store.dispatch('poll/get') } else { - this.$store.dispatch('poll/' + item.table + '/list') + dispatches.push('poll/' + item.table + '/list') + // this.$store.dispatch('poll/' + item.table + '/list') } }) + const requests = dispatches.map(dispatches => this.$store.dispatch(dispatches)) + await Promise.all(requests) + this.watching = true + } catch (error) { this.watching = false + if (axios.isCancel(error)) { console.debug('Watch canceld') } else if (error.response) { + if (error.response.status === 304) { + this.watching = true + } else if (error.response.status === 503) { + console.debug('Server not available, reconnect watch in 30 sec') + await new Promise(resolve => setTimeout(resolve, 30000)) this.watching = true + } else { + console.error('Unhandled error watching polls', error) + } } else if (error.request) { + console.debug('Watch aborted') this.watching = true + } } } |