mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe.git
synced 2024-11-09 18:19:10 +00:00
document makeFetcher a bit
This commit is contained in:
parent
1b6eee0497
commit
d939f2ffbc
1 changed files with 8 additions and 2 deletions
|
@ -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 stopped = false
|
||||||
let timeout = null
|
let timeout = null
|
||||||
let func = () => {}
|
let func = () => {}
|
||||||
|
|
||||||
func = () => {
|
func = () => {
|
||||||
call().finally(() => {
|
promiseCall().finally(() => {
|
||||||
if (stopped) return
|
if (stopped) return
|
||||||
timeout = window.setTimeout(func, interval)
|
timeout = window.setTimeout(func, interval)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue