useTimeoutPoll ​
Use timeout to poll something. It 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
Anthony Fu
Sebastien
David Vallejo
jiadesen
sun0day
Jelf
Wenlu Wang
Changelog ​
v12.0.0-beta.1
on 11/21/2024v10.2.1
on 6/28/2023v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter