{"id":12847,"library":"asynckit","title":"Async Job Utility Library","description":"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.","status":"active","version":"0.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/alexindigo/asynckit","tags":["javascript","async","jobs","parallel","serial","iterator","array","object","stream"],"install":[{"cmd":"npm install asynckit","lang":"bash","label":"npm"},{"cmd":"yarn add asynckit","lang":"bash","label":"yarn"},{"cmd":"pnpm add asynckit","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS `require('asynckit').parallel` is shown in examples. For ESM, use named import. The library itself is CJS but often consumed in mixed environments.","wrong":"const parallel = require('asynckit').parallel;","symbol":"parallel","correct":"import { parallel } from 'asynckit';"},{"note":"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.","wrong":"import serial from 'asynckit/serial';","symbol":"serial","correct":"import { serial } from 'asynckit';"},{"note":"`serialOrdered` is used for serial execution with custom sorting logic. It's also a named export from the main module.","wrong":"const serialOrdered = require('asynckit/serialOrdered');","symbol":"serialOrdered","correct":"import { serialOrdered } from 'asynckit';"}],"quickstart":{"code":"import { parallel } from 'asynckit';\n\nconst source = [1, 1, 4, 16, 64, 32, 8, 2];\nconst expectedResult = [2, 2, 8, 32, 128, 64, 16, 4];\nconst target = [];\n\n// async job accepts one element from the array and a callback function\nfunction asyncJob(item, cb) {\n  const delay = item * 25; // Different delays per item\n  const timeoutId = setTimeout(() => {\n    target.push(item);\n    cb(null, item * 2);\n  }, delay);\n  // Return a function to allow cancelling jobs upon error\n  return clearTimeout.bind(null, timeoutId);\n}\n\nparallel(source, asyncJob, (err, result) => {\n  if (err) {\n    console.error('An error occurred:', err);\n  } else {\n    console.log('Processed result:', result);\n    console.log('Expected result:', expectedResult);\n    console.log('Target array (order of completion):', target);\n    // In a real scenario, you'd assert deep equality here\n    // assert.deepEqual(result, expectedResult);\n  }\n});\n","lang":"javascript","description":"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."},"warnings":[{"fix":"Always ensure `cb(err, data)` is invoked in all possible execution paths of your `asyncJob` function, including error conditions.","message":"When 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always return a cleanup function (e.g., `clearTimeout` for `setTimeout`-based jobs) from your `asyncJob` to enable effective job termination.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Review documentation for `asynckit`'s stream integration if working with large or continuous data streams to optimize performance and resource usage.","message":"Version 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.","severity":"breaking","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to access `parallel` from a `require` or `import` that resolved to `undefined` or a module without the expected exports.","error":"TypeError: Cannot read properties of undefined (reading 'parallel')"},{"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.","cause":"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.","error":"Maximum call stack size exceeded"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null}