useTimeoutPoll ​
Use timeout to poll something. It's will trigger callback after last task is done.
Demo ​
Count: 0
isActive: false
Usage ​
ts
import { useTimeoutPoll } from '@vueuse/core'
const count = ref(0)
async function fetchData() {
await new Promise(resolve => setTimeout(resolve, 1000))
count.value++
}
// Only trigger after last fetch is done
const { isActive, pause, resume } = useTimeoutPoll(fetchData, 1000)
Type Declarations ​
typescript
export declare function useTimeoutPoll(
fn: () => Awaitable<void>,
interval: MaybeRefOrGetter<number>,
timeoutPollOptions?: UseTimeoutFnOptions,
): Pausable
Source ​
Contributors ​
Anthony Fu
David Vallejo
jiadesen
sun0day
Jelf
Wenlu Wang
Changelog ​
v10.2.1
on 6/28/2023v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
v9.0.0-beta.1
on 7/20/2022