yandere_fe/src/services/fetcher/fetcher.js

23 lines
368 B
JavaScript
Raw Normal View History

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)
}
func()
return stopFetcher
}