vue-concurrency is a JavaScript library designed for encapsulating asynchronous operations and managing concurrency within Vue.js applications, leveraging the Composition API. Inspired by `ember-concurrency`, it provides a robust abstraction layer to reduce boilerplate associated with complex async flows. The current active version is `6.0.0-0` (a pre-release) which introduces features like global configuration and pruning, while the `5.x` series provides stable support for Vue 3.3+. Earlier versions (4.x) support Vue 2.7 and 3.2. Key differentiators include built-in TypeScript support, sophisticated async cancellation mechanisms via generator functions and the CAF library, and the ability to provide `AbortSignal` for native fetch/XHR abortion. It offers a reactive derived state (e.g., `isRunning`, `isIdle`, `isFinished`) for tracking operation status and powerful concurrency management strategies such as `drop()`, `restartable()`, and `enqueue()`. The library is actively maintained with regular updates and experimental SSR support.
npm install vue-concurrencyVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to create an asynchronous task for an autocomplete search, manage its loading state (`isRunning`), and apply the `drop` concurrency strategy using Vue 3's Composition API and `vue-concurrency`.
Upgrade your Vue.js project to version 3.3 or later, or downgrade `vue-concurrency` to the `4.x` series.
For Vue 2 projects, upgrade to Vue 2.7. If using an older Vue 2 version with `@vue/composition-api`, use `vue-concurrency` versions prior to `4.0.0`.
For production applications requiring stability, consider using the latest stable `5.x` release. If you choose to use `6.0.0-0`, monitor release notes closely for any API changes before upgrading to future `6.x` versions.
Always define `vue-concurrency` tasks using the `function*` syntax and use `yield` for asynchronous operations that should be cancellable. Example: `useTask(function* () { yield fetchData(); });`Replace `import { Task } from 'vue-concurrency'` with `import type { Task } from 'vue-concurrency'` for all type imports.For Vue 2.7, ensure you are using `vue-concurrency` v4.x. For Vue 3, ensure you meet the peer dependency requirement (v5.x requires Vue 3.3+). Verify your `package.json` and installed Vue version match.
Specify a different concurrency strategy when defining your task, such as `.enqueue()`, `.restartable()`, or `.keepLatest()`, depending on your desired behavior for concurrent task executions. Example: `useTask(...).enqueue()`.
Ensure your `tsconfig.json` `target` and `lib` settings are appropriate, and your bundler's Babel configuration includes the necessary plugins (e.g., `@babel/plugin-transform-regenerator`) or polyfills (`regenerator-runtime/runtime`) if targeting older environments.