diff options
| author | Shpuld Shpuldson <shp@cock.li> | 2020-09-02 20:40:47 +0300 |
|---|---|---|
| committer | Shpuld Shpuldson <shp@cock.li> | 2020-09-02 20:40:47 +0300 |
| commit | 2d914c331eea5f5b9036e10ef3d937628891b9e1 (patch) | |
| tree | faee1fb83a9d71e4f43a4e8ea4232c2cf543b84d /src/services/fetcher/fetcher.js | |
| parent | acc45b49a55a5c173abdeac8c89d16395f92bc01 (diff) | |
replace setInterval for timelne, notifications and follow requests
Diffstat (limited to 'src/services/fetcher/fetcher.js')
| -rw-r--r-- | src/services/fetcher/fetcher.js | 23 |
1 files changed, 23 insertions, 0 deletions
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 +} |
