useAsyncQueue

useAsyncQueue

各非同期タスクを順番に実行し、現在のタスクの結果を次のタスクに渡します

使用法

import { useAsyncQueue } from '@vueuse/core'

function p1() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(1000)
    }, 10)
  })
}

function p2(result: number) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(1000 + result)
    }, 20)
  })
}

const { activeIndex, result } = useAsyncQueue([p1, p2])

console.log(activeIndex.value) // 現在保留中のタスクのインデックス

console.log(result) // タスクの結果