Registry / http-networking / asynckit

asynckit

JSON →
library0.4.2-r2702203jsnpmunverified

asynckit is a minimal utility library designed to manage asynchronous jobs, providing structured execution patterns for parallel and serial processing over arrays and objects. It's currently at version 0.5.0, with its latest release (v0.5.0) focusing on housecleaning and minor package optimizations. The library does not follow a strict release cadence but updates periodically for maintenance and feature enhancements, such as the stream support added in v0.4.0. Its core differentiator lies in its robust handling of async operations to prevent 'Maximum call stack size exceeded' errors from synchronous iterators, and its ability to terminate leftover jobs upon an error event, making it suitable for scenarios requiring resilient and controlled asynchronous execution flows. It offers built-in and custom sorting for ordered serial operations.

npm install asynckit
INSTALL
IMPORT
SIG · ASYNCKIT
A
asynckit
http-networkingjavascriptv0.4.2-r2702203
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.

parallel
import { parallel } from 'asynckit';
const parallel = require('asynckit').parallel;
CommonJS `require('asynckit').parallel` is shown in examples. For ESM, use named import. The library itself is CJS but often consumed in mixed environments.
serial
import { serial } from 'asynckit';
import serial from 'asynckit/serial';
Both `serial` and `parallel` are named exports from the main entry point. Direct subpath imports like `asynckit/parallel` might work but are not the canonical way for ESM.
serialOrdered
import { serialOrdered } from 'asynckit';
const serialOrdered = require('asynckit/serialOrdered');
`serialOrdered` is used for serial execution with custom sorting logic. It's also a named export from the main module.

This quickstart demonstrates parallel processing of an array with asynchronous jobs, showing how to define an async task and handle its completion and potential abortion.

import { parallel } from 'asynckit'; const source = [1, 1, 4, 16, 64, 32, 8, 2]; const expectedResult = [2, 2, 8, 32, 128, 64, 16, 4]; const target = []; // async job accepts one element from the array and a callback function function asyncJob(item, cb) { const delay = item * 25; // Different delays per item const timeoutId = setTimeout(() => { target.push(item); cb(null, item * 2); }, delay); // Return a function to allow cancelling jobs upon error return clearTimeout.bind(null, timeoutId); } parallel(source, asyncJob, (err, result) => { if (err) { console.error('An error occurred:', err); } else { console.log('Processed result:', result); console.log('Expected result:', expectedResult); console.log('Target array (order of completion):', target); // In a real scenario, you'd assert deep equality here // assert.deepEqual(result, expectedResult); } });
Debug
Known issues
gotchaWhen using `asyncJob` functions, ensure the callback `cb(err, data)` is always called eventually. Forgetting to call `cb` will leave jobs hanging indefinitely, leading to resource leaks or timeouts.
fix
Always ensure `cb(err, data)` is invoked in all possible execution paths of your `asyncJob` function, including error conditions.
affects: >=0.1.0
gotchaThe abort function returned by `asyncJob` is crucial for proper error handling and resource cleanup in parallel operations. If not provided, `asynckit` cannot terminate 'leftover' jobs upon an error, potentially wasting resources.
fix
Always return a cleanup function (e.g., `clearTimeout` for `setTimeout`-based jobs) from your `asyncJob` to enable effective job termination.
affects: >=0.1.0
breakingVersion 0.4.0 introduced streams support. While not a direct breaking change, existing code might not leverage the new stream capabilities, potentially leading to less efficient processing for stream-based data sources.
fix
Review documentation for `asynckit`'s stream integration if working with large or continuous data streams to optimize performance and resource usage.
affects: >=0.4.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'parallel')
Attempting to access `parallel` from a `require` or `import` that resolved to `undefined` or a module without the expected exports.
fix
Ensure `asynckit` is correctly installed (`npm install asynckit`) and that the import path is correct: `const parallel = require('asynckit').parallel;` for CommonJS or `import { parallel } from 'asynckit';` for ESM.
Maximum call stack size exceeded
Synchronous iterators or excessively deep synchronous recursive calls within the `asyncJob` or the iterator function, particularly when dealing with large datasets without proper async breaks.
fix
Verify that your `asyncJob` functions are genuinely asynchronous, using `setTimeout`, Promises, or other async mechanisms. `asynckit` is designed to prevent this by ensuring async breaks, but user-defined synchronous logic within the job can still trigger it.
Upgrade
Version history
0.4.2-r2702203latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
asynckit — npm install asynckit · libregistry