useTimeoutPoll
Use timeout to poll something. It's will trigger callback after last task is done.
Demo
Count: 0
isActive: false
Usage
import { useTimeoutPoll } from '@vueuse/core'
const count = ref(0)
const fetchData = async () => {
await promiseTimeout(1000)
count.value++
}
// Only trigger after last fetch is done
const { isActive, pause, resume } = useTimeoutPoll(fetchData, 1000)
import { useTimeoutPoll } from '@vueuse/core'
const count = ref(0)
const fetchData = async () => {
await promiseTimeout(1000)
count.value++
}
// Only trigger after last fetch is done
const { isActive, pause, resume } = useTimeoutPoll(fetchData, 1000)
Type Declarations
export declare function useTimeoutPoll(
fn: () => Awaitable<void>,
interval: MaybeRef<number>,
timeoutPollOptions?: TimeoutFnOptions
): Pausable
export declare function useTimeoutPoll(
fn: () => Awaitable<void>,
interval: MaybeRef<number>,
timeoutPollOptions?: TimeoutFnOptions
): Pausable
Source
Contributors
Anthony Fu
Wenlu Wang
Changelog
v8.0.0-beta.1
on 3/5/2022