From 2d914c331eea5f5b9036e10ef3d937628891b9e1 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 20:40:47 +0300 Subject: [PATCH 1/7] replace setInterval for timelne, notifications and follow requests --- src/modules/api.js | 2 +- src/services/fetcher/fetcher.js | 23 +++++++++++++++++++ .../follow_request_fetcher.service.js | 4 ++-- .../notifications_fetcher.service.js | 7 +++--- .../timeline_fetcher.service.js | 7 +++--- 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 src/services/fetcher/fetcher.js diff --git a/src/modules/api.js b/src/modules/api.js index 5e213f0d..7ddd8dde 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -20,7 +20,7 @@ const api = { state.fetchers[fetcherName] = fetcher }, removeFetcher (state, { fetcherName, fetcher }) { - window.clearInterval(fetcher) + state.fetchers[fetcherName]() delete state.fetchers[fetcherName] }, setWsToken (state, token) { diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js new file mode 100644 index 00000000..1d9239cc --- /dev/null +++ b/src/services/fetcher/fetcher.js @@ -0,0 +1,23 @@ + +export const makeFetcher = (call, interval) => { + let stopped = false + let timeout = null + let func = () => {} + + func = () => { + call().finally(() => { + console.log('callbacks') + if (stopped) return + timeout = window.setTimeout(func, interval) + }) + } + + const stopFetcher = () => { + stopped = true + window.cancelTimeout(timeout) + } + + func() + + return stopFetcher +} diff --git a/src/services/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_request_fetcher.service.js index 93fac9bc..8d1aba7b 100644 --- a/src/services/follow_request_fetcher/follow_request_fetcher.service.js +++ b/src/services/follow_request_fetcher/follow_request_fetcher.service.js @@ -1,4 +1,5 @@ import apiService from '../api/api.service.js' +import { makeFetcher } from '../fetcher/fetcher.js' const fetchAndUpdate = ({ store, credentials }) => { return apiService.fetchFollowRequests({ credentials }) @@ -10,9 +11,8 @@ const fetchAndUpdate = ({ store, credentials }) => { } const startFetching = ({ credentials, store }) => { - fetchAndUpdate({ credentials, store }) const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) - return setInterval(boundFetchAndUpdate, 10000) + return makeFetcher(boundFetchAndUpdate, 10000) } const followRequestFetcher = { diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index 80be02ca..2a3a17be 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -1,4 +1,5 @@ import apiService from '../api/api.service.js' +import makeFetcher from '../fetcher/fetcher.js' const update = ({ store, notifications, older }) => { store.dispatch('setNotificationsError', { value: false }) @@ -39,6 +40,7 @@ const fetchAndUpdate = ({ store, credentials, older = false }) => { args['since'] = Math.max(...readNotifsIds) fetchNotifications({ store, args, older }) } + return result } } @@ -53,13 +55,12 @@ const fetchNotifications = ({ store, args, older }) => { } const startFetching = ({ credentials, store }) => { - fetchAndUpdate({ credentials, store }) - const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) // Initially there's set flag to silence all desktop notifications so // that there won't spam of them when user just opened up the FE we // reset that flag after a while to show new notifications once again. setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000) - return setInterval(boundFetchAndUpdate, 10000) + const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store, refetch: true }) + return makeFetcher(boundFetchAndUpdate, 10000) } const notificationsFetcher = { diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index d0cddf84..8bbec2c7 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -1,6 +1,7 @@ import { camelCase } from 'lodash' import apiService from '../api/api.service.js' +import { makeFetcher } from '../fetcher/fetcher.js' const update = ({ store, statuses, timeline, showImmediately, userId, pagination }) => { const ccTimeline = camelCase(timeline) @@ -70,9 +71,9 @@ const startFetching = ({ timeline = 'friends', credentials, store, userId = fals const timelineData = rootState.statuses.timelines[camelCase(timeline)] const showImmediately = timelineData.visibleStatuses.length === 0 timelineData.userId = userId - fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) - const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId, tag }) - return setInterval(boundFetchAndUpdate, 10000) + const boundFetchAndUpdate = () => + fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) + return makeFetcher(boundFetchAndUpdate, 10000) } const timelineFetcher = { fetchAndUpdate, From 1b6eee049700f6fbb0c2e43877ead3ef4cf3041b Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 21:01:31 +0300 Subject: [PATCH 2/7] change chats to use custom makeFetcher --- src/components/chat/chat.js | 5 +++-- src/modules/chats.js | 11 +++++------ src/services/fetcher/fetcher.js | 3 +-- .../notifications_fetcher.service.js | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/chat/chat.js b/src/components/chat/chat.js index 9c4e5b05..2062643d 100644 --- a/src/components/chat/chat.js +++ b/src/components/chat/chat.js @@ -5,6 +5,7 @@ import ChatMessage from '../chat_message/chat_message.vue' import PostStatusForm from '../post_status_form/post_status_form.vue' import ChatTitle from '../chat_title/chat_title.vue' import chatService from '../../services/chat_service/chat_service.js' +import { makeFetcher } from '../../services/fetcher/fetcher.js' import { getScrollPosition, getNewTopPosition, isBottomedOut, scrollableContainerHeight } from './chat_layout_utils.js' const BOTTOMED_OUT_OFFSET = 10 @@ -246,7 +247,7 @@ const Chat = { const fetchOlderMessages = !!maxId const sinceId = fetchLatest && chatMessageService.lastMessage && chatMessageService.lastMessage.id - this.backendInteractor.chatMessages({ id: chatId, maxId, sinceId }) + return this.backendInteractor.chatMessages({ id: chatId, maxId, sinceId }) .then((messages) => { // Clear the current chat in case we're recovering from a ws connection loss. if (isFirstFetch) { @@ -287,7 +288,7 @@ const Chat = { }, doStartFetching () { this.$store.dispatch('startFetchingCurrentChat', { - fetcher: () => setInterval(() => this.fetchChat({ fetchLatest: true }), 5000) + fetcher: () => makeFetcher(() => this.fetchChat({ fetchLatest: true }), 5000) }) this.fetchChat({ isFirstFetch: true }) }, diff --git a/src/modules/chats.js b/src/modules/chats.js index c7609018..45e4bdcc 100644 --- a/src/modules/chats.js +++ b/src/modules/chats.js @@ -3,6 +3,7 @@ import { find, omitBy, orderBy, sumBy } from 'lodash' import chatService from '../services/chat_service/chat_service.js' import { parseChat, parseChatMessage } from '../services/entity_normalizer/entity_normalizer.service.js' import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js' +import { makeFetcher } from '../services/fetcher/fetcher.js' const emptyChatList = () => ({ data: [], @@ -42,12 +43,10 @@ const chats = { actions: { // Chat list startFetchingChats ({ dispatch, commit }) { - const fetcher = () => { - dispatch('fetchChats', { latest: true }) - } + const fetcher = () => dispatch('fetchChats', { latest: true }) fetcher() commit('setChatListFetcher', { - fetcher: () => setInterval(() => { fetcher() }, 5000) + fetcher: () => makeFetcher(fetcher, 5000) }) }, stopFetchingChats ({ commit }) { @@ -113,14 +112,14 @@ const chats = { setChatListFetcher (state, { commit, fetcher }) { const prevFetcher = state.chatListFetcher if (prevFetcher) { - clearInterval(prevFetcher) + prevFetcher() } state.chatListFetcher = fetcher && fetcher() }, setCurrentChatFetcher (state, { fetcher }) { const prevFetcher = state.fetcher if (prevFetcher) { - clearInterval(prevFetcher) + prevFetcher() } state.fetcher = fetcher && fetcher() }, diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js index 1d9239cc..95b8c9d3 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/fetcher/fetcher.js @@ -6,7 +6,6 @@ export const makeFetcher = (call, interval) => { func = () => { call().finally(() => { - console.log('callbacks') if (stopped) return timeout = window.setTimeout(func, interval) }) @@ -14,7 +13,7 @@ export const makeFetcher = (call, interval) => { const stopFetcher = () => { stopped = true - window.cancelTimeout(timeout) + window.clearTimeout(timeout) } func() diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index 2a3a17be..c69d5b17 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -1,5 +1,5 @@ import apiService from '../api/api.service.js' -import makeFetcher from '../fetcher/fetcher.js' +import { makeFetcher } from '../fetcher/fetcher.js' const update = ({ store, notifications, older }) => { store.dispatch('setNotificationsError', { value: false }) From d939f2ffbcb632361a0362f0f2049f99160dee64 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 21:08:06 +0300 Subject: [PATCH 3/7] document makeFetcher a bit --- src/services/fetcher/fetcher.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js index 95b8c9d3..5a6ed4b8 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/fetcher/fetcher.js @@ -1,11 +1,17 @@ -export const makeFetcher = (call, interval) => { +// makeFetcher - replacement for setInterval for fetching, starts counting +// the interval only after a request is done instead of immediately. +// promiseCall is a function that returns a promise, it's called when created +// and after every interval. +// interval is the interval delay in ms. + +export const makeFetcher = (promiseCall, interval) => { let stopped = false let timeout = null let func = () => {} func = () => { - call().finally(() => { + promiseCall().finally(() => { if (stopped) return timeout = window.setTimeout(func, interval) }) From 4d080a1654ff56e9875c49486457a1ac8e19297e Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 21:26:02 +0300 Subject: [PATCH 4/7] add mention to changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 675c4b5b..e5521b83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Polls will be hidden with status content if "Collapse posts with subjects" is enabled and the post is collapsed. +### Fixed +- Network fetches don't pile up anymore but wait for previous ones to finish to reduce throttling. + ## [2.1.0] - 2020-08-28 ### Added - Autocomplete domains from list of known instances From 5b403ba7d13eaf851ae43e814c583ceb018e2d20 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 22:12:50 +0300 Subject: [PATCH 5/7] fix timeline showimmediately being set wrongly --- src/services/fetcher/fetcher.js | 8 ++++---- .../follow_request_fetcher.service.js | 1 + .../notifications_fetcher.service.js | 3 ++- src/services/timeline_fetcher/timeline_fetcher.service.js | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js index 5a6ed4b8..aae1c2cc 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/fetcher/fetcher.js @@ -1,9 +1,9 @@ // makeFetcher - replacement for setInterval for fetching, starts counting // the interval only after a request is done instead of immediately. -// promiseCall is a function that returns a promise, it's called when created -// and after every interval. -// interval is the interval delay in ms. +// - promiseCall is a function that returns a promise, it's called the first +// time after the first interval. +// - interval is the interval delay in ms. export const makeFetcher = (promiseCall, interval) => { let stopped = false @@ -22,7 +22,7 @@ export const makeFetcher = (promiseCall, interval) => { window.clearTimeout(timeout) } - func() + timeout = window.setTimeout(func, interval) return stopFetcher } diff --git a/src/services/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_request_fetcher.service.js index 8d1aba7b..bec434aa 100644 --- a/src/services/follow_request_fetcher/follow_request_fetcher.service.js +++ b/src/services/follow_request_fetcher/follow_request_fetcher.service.js @@ -12,6 +12,7 @@ const fetchAndUpdate = ({ store, credentials }) => { const startFetching = ({ credentials, store }) => { const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) + boundFetchAndUpdate() return makeFetcher(boundFetchAndUpdate, 10000) } diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index c69d5b17..90988fc4 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -59,7 +59,8 @@ const startFetching = ({ credentials, store }) => { // that there won't spam of them when user just opened up the FE we // reset that flag after a while to show new notifications once again. setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000) - const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store, refetch: true }) + const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) + boundFetchAndUpdate() return makeFetcher(boundFetchAndUpdate, 10000) } diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index 8bbec2c7..9f585f68 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -71,8 +71,9 @@ const startFetching = ({ timeline = 'friends', credentials, store, userId = fals const timelineData = rootState.statuses.timelines[camelCase(timeline)] const showImmediately = timelineData.visibleStatuses.length === 0 timelineData.userId = userId + fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) const boundFetchAndUpdate = () => - fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) + fetchAndUpdate({ timeline, credentials, store, userId, tag }) return makeFetcher(boundFetchAndUpdate, 10000) } const timelineFetcher = { From 3fb35e8123d3a8cd151571b315b7ec4d7e0875c7 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 4 Sep 2020 11:19:53 +0300 Subject: [PATCH 6/7] rename to promiseInterval --- src/components/chat/chat.js | 4 ++-- src/modules/api.js | 2 +- src/modules/chats.js | 4 ++-- .../follow_request_fetcher.service.js | 4 ++-- .../notifications_fetcher.service.js | 4 ++-- .../fetcher.js => promise_interval/promise_interval.js} | 8 ++++---- src/services/timeline_fetcher/timeline_fetcher.service.js | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) rename src/services/{fetcher/fetcher.js => promise_interval/promise_interval.js} (68%) diff --git a/src/components/chat/chat.js b/src/components/chat/chat.js index 2062643d..15123885 100644 --- a/src/components/chat/chat.js +++ b/src/components/chat/chat.js @@ -5,7 +5,7 @@ import ChatMessage from '../chat_message/chat_message.vue' import PostStatusForm from '../post_status_form/post_status_form.vue' import ChatTitle from '../chat_title/chat_title.vue' import chatService from '../../services/chat_service/chat_service.js' -import { makeFetcher } from '../../services/fetcher/fetcher.js' +import { promiseInterval } from '../../services/promise_interval/promise_interval.js' import { getScrollPosition, getNewTopPosition, isBottomedOut, scrollableContainerHeight } from './chat_layout_utils.js' const BOTTOMED_OUT_OFFSET = 10 @@ -288,7 +288,7 @@ const Chat = { }, doStartFetching () { this.$store.dispatch('startFetchingCurrentChat', { - fetcher: () => makeFetcher(() => this.fetchChat({ fetchLatest: true }), 5000) + fetcher: () => promiseInterval(() => this.fetchChat({ fetchLatest: true }), 5000) }) this.fetchChat({ isFirstFetch: true }) }, diff --git a/src/modules/api.js b/src/modules/api.js index 7ddd8dde..73511442 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -20,7 +20,7 @@ const api = { state.fetchers[fetcherName] = fetcher }, removeFetcher (state, { fetcherName, fetcher }) { - state.fetchers[fetcherName]() + state.fetchers[fetcherName].stop() delete state.fetchers[fetcherName] }, setWsToken (state, token) { diff --git a/src/modules/chats.js b/src/modules/chats.js index 45e4bdcc..60273a44 100644 --- a/src/modules/chats.js +++ b/src/modules/chats.js @@ -3,7 +3,7 @@ import { find, omitBy, orderBy, sumBy } from 'lodash' import chatService from '../services/chat_service/chat_service.js' import { parseChat, parseChatMessage } from '../services/entity_normalizer/entity_normalizer.service.js' import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js' -import { makeFetcher } from '../services/fetcher/fetcher.js' +import { promiseInterval } from '../services/promise_interval/promise_interval.js' const emptyChatList = () => ({ data: [], @@ -46,7 +46,7 @@ const chats = { const fetcher = () => dispatch('fetchChats', { latest: true }) fetcher() commit('setChatListFetcher', { - fetcher: () => makeFetcher(fetcher, 5000) + fetcher: () => promiseInterval(fetcher, 5000) }) }, stopFetchingChats ({ commit }) { diff --git a/src/services/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_request_fetcher.service.js index bec434aa..74af4081 100644 --- a/src/services/follow_request_fetcher/follow_request_fetcher.service.js +++ b/src/services/follow_request_fetcher/follow_request_fetcher.service.js @@ -1,5 +1,5 @@ import apiService from '../api/api.service.js' -import { makeFetcher } from '../fetcher/fetcher.js' +import { promiseInterval } from '../promise_interval/promise_interval.js' const fetchAndUpdate = ({ store, credentials }) => { return apiService.fetchFollowRequests({ credentials }) @@ -13,7 +13,7 @@ const fetchAndUpdate = ({ store, credentials }) => { const startFetching = ({ credentials, store }) => { const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) boundFetchAndUpdate() - return makeFetcher(boundFetchAndUpdate, 10000) + return promiseInterval(boundFetchAndUpdate, 10000) } const followRequestFetcher = { diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index 90988fc4..c908b644 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -1,5 +1,5 @@ import apiService from '../api/api.service.js' -import { makeFetcher } from '../fetcher/fetcher.js' +import { promiseInterval } from '../promise_interval/promise_interval.js' const update = ({ store, notifications, older }) => { store.dispatch('setNotificationsError', { value: false }) @@ -61,7 +61,7 @@ const startFetching = ({ credentials, store }) => { setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000) const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) boundFetchAndUpdate() - return makeFetcher(boundFetchAndUpdate, 10000) + return promiseInterval(boundFetchAndUpdate, 10000) } const notificationsFetcher = { diff --git a/src/services/fetcher/fetcher.js b/src/services/promise_interval/promise_interval.js similarity index 68% rename from src/services/fetcher/fetcher.js rename to src/services/promise_interval/promise_interval.js index aae1c2cc..ee46a236 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/promise_interval/promise_interval.js @@ -1,11 +1,11 @@ -// makeFetcher - replacement for setInterval for fetching, starts counting -// the interval only after a request is done instead of immediately. +// promiseInterval - replacement for setInterval for promises, starts counting +// the interval only after a promise is done instead of immediately. // - promiseCall is a function that returns a promise, it's called the first // time after the first interval. // - interval is the interval delay in ms. -export const makeFetcher = (promiseCall, interval) => { +export const promiseInterval = (promiseCall, interval) => { let stopped = false let timeout = null let func = () => {} @@ -24,5 +24,5 @@ export const makeFetcher = (promiseCall, interval) => { timeout = window.setTimeout(func, interval) - return stopFetcher + return { stop: stopFetcher } } diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index 9f585f68..72ea4890 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -1,7 +1,7 @@ import { camelCase } from 'lodash' import apiService from '../api/api.service.js' -import { makeFetcher } from '../fetcher/fetcher.js' +import { promiseInterval } from '../promise_interval/promise_interval.js' const update = ({ store, statuses, timeline, showImmediately, userId, pagination }) => { const ccTimeline = camelCase(timeline) @@ -74,7 +74,7 @@ const startFetching = ({ timeline = 'friends', credentials, store, userId = fals fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId, tag }) - return makeFetcher(boundFetchAndUpdate, 10000) + return promiseInterval(boundFetchAndUpdate, 10000) } const timelineFetcher = { fetchAndUpdate, From c89ac79140e059f89d4da88ce49c9bb24db4cc20 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 4 Sep 2020 11:22:14 +0300 Subject: [PATCH 7/7] fix chat fetcher stops, change fetcher code --- src/modules/chats.js | 4 ++-- src/services/promise_interval/promise_interval.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/chats.js b/src/modules/chats.js index 60273a44..8e2fabb6 100644 --- a/src/modules/chats.js +++ b/src/modules/chats.js @@ -112,14 +112,14 @@ const chats = { setChatListFetcher (state, { commit, fetcher }) { const prevFetcher = state.chatListFetcher if (prevFetcher) { - prevFetcher() + prevFetcher.stop() } state.chatListFetcher = fetcher && fetcher() }, setCurrentChatFetcher (state, { fetcher }) { const prevFetcher = state.fetcher if (prevFetcher) { - prevFetcher() + prevFetcher.stop() } state.fetcher = fetcher && fetcher() }, diff --git a/src/services/promise_interval/promise_interval.js b/src/services/promise_interval/promise_interval.js index ee46a236..cf17970d 100644 --- a/src/services/promise_interval/promise_interval.js +++ b/src/services/promise_interval/promise_interval.js @@ -8,9 +8,8 @@ export const promiseInterval = (promiseCall, interval) => { let stopped = false let timeout = null - let func = () => {} - func = () => { + const func = () => { promiseCall().finally(() => { if (stopped) return timeout = window.setTimeout(func, interval)