Skip to content

useTimeoutPoll ​

Category
Export Size
407 B
Last Changed
9 months ago

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 ​

Source • Demo • Docs

Contributors ​

Anthony Fu
David Vallejo
jiadesen
sun0day
Jelf
Wenlu Wang

Changelog ​

v10.2.1 on 6/28/2023
7a897 - fix: unexpected immediate execution (#3159)
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
v9.0.0-beta.1 on 7/20/2022
4ca70 - fix(useTimeoutFn,useTimeout)!: rename type TimeoutOptions to UseTimeoutOptions and TimeoutFnOptions to UseTimeoutFnOptions (#1944)

Released under the MIT License.