2020-09-02 10:40:47 -07:00
|
|
|
|
|
|
|
export const makeFetcher = (call, interval) => {
|
|
|
|
let stopped = false
|
|
|
|
let timeout = null
|
|
|
|
let func = () => {}
|
|
|
|
|
|
|
|
func = () => {
|
|
|
|
call().finally(() => {
|
|
|
|
if (stopped) return
|
|
|
|
timeout = window.setTimeout(func, interval)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const stopFetcher = () => {
|
|
|
|
stopped = true
|
2020-09-02 11:01:31 -07:00
|
|
|
window.clearTimeout(timeout)
|
2020-09-02 10:40:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func()
|
|
|
|
|
|
|
|
return stopFetcher
|
|
|
|
}
|