Registry / web-framework / vue-concurrency

vue-concurrency

JSON →
library6.0.0-0jsnpmunverified

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-concurrency
INSTALL
IMPORT
SIG · VUE-CONCURRENCY
V
vue-concurrency
web-frameworkjavascriptv6.0.0-0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useTask
import { useTask } from 'vue-concurrency'
const useTask = require('vue-concurrency')
`useTask` is the primary Composition API hook for defining and managing tasks. CommonJS `require` syntax is generally incorrect for modern Vue 3 projects which primarily use ESM.
TaskInstance
import type { TaskInstance } from 'vue-concurrency'
import { TaskInstance } from 'vue-concurrency'
`TaskInstance` is a TypeScript type representing a single execution of a task. It should be imported as a type (`import type`) to ensure type-only import and avoid potential runtime issues or bundling bloat.
Task
import type { Task } from 'vue-concurrency'
import Task from 'vue-concurrency'
`Task` is a TypeScript type for the task definition itself. Like `TaskInstance`, it should be imported as a type. There is no default export for `Task` or other core utilities.

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`.

import { defineComponent, ref } from 'vue'; import { useTask } from 'vue-concurrency'; export default defineComponent({ setup() { const searchTerm = ref(''); const searchResults = ref<string[]>([]); const error = ref<string | null>(null); // Define an asynchronous task for searching const searchTask = useTask(function* (term: string) { error.value = null; searchResults.value = []; if (!term) { return; } try { // Simulate an API call with a delay. `yield` makes it cancellable. yield new Promise(resolve => setTimeout(resolve, 500)); // Simulate a potential network error if (Math.random() < 0.2) { throw new Error('Simulated network error!'); } const results = Array.from({ length: 3 }, (_, i) => `${term} result ${i + 1}`); searchResults.value = results; } catch (e: any) { error.value = e.message; } }).drop(); // Concurrency strategy: if a new search starts, previous one is cancelled/dropped const onSearchInput = (event: Event) => { const input = event.target as HTMLInputElement; searchTerm.value = input.value; // Perform the task whenever the input changes searchTask.perform(input.value); }; return { searchTerm, searchResults, error, searchTask, onSearchInput }; }, template: ` <div style="padding: 20px; font-family: sans-serif;"> <h1>Autocomplete Search</h1> <input type="text" v-model="searchTerm" @input="onSearchInput" placeholder="Type to search..." style="padding: 8px; font-size: 16px; width: 300px;" /> <div v-if="searchTask.isRunning" style="margin-top: 10px; color: gray;">Searching...</div> <div v-if="error" style="margin-top: 10px; color: red; font-weight: bold;">Error: {{ error }}</div> <ul v-if="searchResults.length && !searchTask.isRunning" style="list-style: none; padding: 0; margin-top: 10px;"> <li v-for="result in searchResults" :key="result" style="padding: 5px 0; border-bottom: 1px solid #eee;">{{ result }}</li> </ul> <div v-if="!searchTerm && !searchTask.isRunning && !error" style="margin-top: 10px; color: #aaa;">Start typing to see results</div> </div> ` });
Debug
Known issues
breakingVersion 5.x of `vue-concurrency` requires Vue 3.3 or newer. Applications using older Vue 3 versions (e.g., 3.0-3.2) or Vue 2.7 must remain on `vue-concurrency` v4.x.
fix
Upgrade your Vue.js project to version 3.3 or later, or downgrade `vue-concurrency` to the `4.x` series.
affects: >=5.0.0
breakingVersion 4.x introduced support for Vue 2.7 and 3.2, which required changes that deprecated earlier Vue 2 versions used with `@vue/composition-api`. For Vue 2 projects, only Vue 2.7 is officially supported by 4.x.
fix
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`.
affects: >=4.0.0
gotchaThe currently provided version `6.0.0-0` is a pre-release (`-0` suffix). While it introduces new features like global configuration and pruning, its API might not be stable, and it may contain bugs or breaking changes in subsequent `6.x` pre-releases or the final `6.0.0` release. Using pre-releases in production is not recommended for stability.
fix
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.
affects: 6.0.0-0
gotcha`vue-concurrency` leverages ES generator functions (`function*`) for automatic async cancellation. Defining tasks with plain `async`/`await` functions will prevent cancellation from working correctly, leading to potential resource leaks or unexpected behavior when concurrency strategies like `drop()` or `restartable()` are applied.
fix
Always define `vue-concurrency` tasks using the `function*` syntax and use `yield` for asynchronous operations that should be cancellable. Example: `useTask(function* () { yield fetchData(); });`
affects: >=2.4.0
gotchaWhen importing TypeScript types from `vue-concurrency` (e.g., `Task`, `TaskInstance`), it's best practice to use `import type { ... } from 'vue-concurrency'`. While `import { ... } from 'vue-concurrency'` might work in some build environments, `import type` explicitly signals a type-only import, preventing potential runtime errors or unnecessary bundle size increases.
fix
Replace `import { Task } from 'vue-concurrency'` with `import type { Task } from 'vue-concurrency'` for all type imports.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'setup') OR Error: [Vue warn]: Failed to resolve component: <ComponentName>
`vue-concurrency` is being used in a Vue 2 project without Vue 2.7, or with an incompatible version of `@vue/composition-api`, or an incorrect Vue 3 version.
fix
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.
Error: [vue-concurrency] Task 'myTask' is already running. You attempted to perform 'myTask' but it is already running. If you want to run multiple tasks concurrently, use one of the concurrency strategies like 'enqueue' or 'restartable'.
By default, `vue-concurrency` tasks have a `drop` concurrency strategy which prevents multiple instances of the same task from running simultaneously. Attempting to `perform()` a task that is already running will trigger this error.
fix
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()`.
SyntaxError: Unexpected token '*' OR ReferenceError: regeneratorRuntime is not defined
Your build environment (Babel, TypeScript, Webpack, Vite) is not correctly configured to transpile ES generator functions (`function*`) for your target browser or Node.js environment, or `regenerator-runtime` is missing.
fix
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.
Upgrade
Version history
6.0.0-0latest on npm
Audit
Dependencies
vuerequiredRequired peer dependency for Vue integration. Version 5.x requires Vue ^3.3, while 4.x supports Vue ^2.7 || ^3.2.
Agent activity
14 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
vue-concurrency — npm install vue-concurrency · libregistry