{"name":"js-queue","version":"3.0.0","keywords":["queue","fifo","task-queue","flow-control","async","browser","node","esm","commonjs"],"author":{"name":"Brandon Nozaki Miller"},"license":"MIT","_id":"js-queue@3.0.0","maintainers":[{"name":"riaevangelist","email":"brandon@diginow.it"}],"homepage":"https://riaevangelist.github.io/js-queue/","bugs":{"url":"https://github.com/RIAEvangelist/js-queue/issues"},"dist":{"shasum":"36b6da74bc28a11324470d0094d59bbb7e79c418","tarball":"http://registry-npm.ywwl.com/js-queue/download/js-queue-3.0.0.tgz","fileCount":11,"integrity":"sha512-LrudN9nzY5MjsysnhKE/Tp0MO8M5BHPeaEwNVBzYyrIJir2AkbrhNpun8SWQo6XpHPPO2DVESRAg1a4VlF8/hw==","signatures":[{"sig":"MEUCIEtGDGKhvwDDeAcsdMmC1mMU5WZfvXNp8TwrdoStEiZ8AiEA2QZlgzF5v+xz2cIQBfAGth9ccpLWhtu7wv+b+lsIv5g=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/js-queue@3.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":1466578,"size":1441405,"noattachment":false,"key":"/js-queue/-/js-queue-3.0.0.tgz"},"main":"./queue.cjs","type":"module","module":"./queue.js","browser":"./queue.js","engines":{"node":">=12.22.0"},"exports":{".":{"import":"./queue.js","default":"./queue.js","require":"./queue.cjs"},"./queue":{"import":"./queue.js","require":"./queue.cjs"},"./stack":{"import":"./stack.js","require":"./stack.cjs"},"./queue.js":{"import":"./queue.js","require":"./queue.cjs"},"./stack.js":{"import":"./stack.js","require":"./stack.cjs"},"./package.json":"./package.json","./queue-vanilla.js":"./queue-vanilla.js"},"gitHead":"4fdb2bf9e40d35f9d5c2524ed4c4b1c1bffdc0a9","scripts":{"test":"node ./scripts/test.js","check":"npm test && npm run coverage:node","start":"node ./scripts/serve.js","coverage":"vanilla-test coverage","test:core":"node ./scripts/test.js core","test:docs":"node ./scripts/test.js docs","test:legacy":"node ./scripts/test.js legacy","test:server":"node ./scripts/test.js server","test:package":"node ./scripts/test.js package","coverage:node":"vanilla-test coverage node","coverage:chrome":"vanilla-test coverage chrome"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:b236f4be-1e04-444e-a7f8-92fa73c5581a"}},"repository":{"url":"git+https://github.com/RIAEvangelist/js-queue.git","type":"git"},"_npmVersion":"11.17.0","description":"A tiny FIFO task queue with explicit flow control for Node and browsers","directories":{},"sideEffects":["./queue-vanilla.js"],"_nodeVersion":"24.19.0","dependencies":{"easy-stack":"2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"vanilla-test":"2.1.1"},"_npmOperationalInternal":{"tmp":"tmp/js-queue_3.0.0_1786899085869_0.8101566725709264","host":"s3://npm-registry-packages-npm-production"},"readme":"![js-queue — explicit FIFO flow control for JavaScript](./assets/js-queue-header.png)\n\n# js-queue\n\nA tiny first-in-first-out task queue with explicit flow control. Add functions, let the queue start automatically, and call `this.next()` when each task is ready to release the next one.\n\n[Documentation](https://riaevangelist.github.io/js-queue/) · [Quick start](https://riaevangelist.github.io/js-queue/guide/) · [API](https://riaevangelist.github.io/js-queue/api/) · [Patterns](https://riaevangelist.github.io/js-queue/patterns/) · [Browser use](https://riaevangelist.github.io/js-queue/browser/) · [Examples](https://riaevangelist.github.io/js-queue/examples/) · [Playground](https://riaevangelist.github.io/js-queue/playground/) · [Performance](https://riaevangelist.github.io/js-queue/performance/) · [Testing](https://riaevangelist.github.io/js-queue/testing/)\n\n[![CI](https://github.com/RIAEvangelist/js-queue/actions/workflows/ci.yml/badge.svg)](https://github.com/RIAEvangelist/js-queue/actions/workflows/ci.yml)\n[![Pages](https://github.com/RIAEvangelist/js-queue/actions/workflows/pages.yml/badge.svg)](https://github.com/RIAEvangelist/js-queue/actions/workflows/pages.yml)\n[![npm version](https://img.shields.io/npm/v/js-queue.svg)](https://www.npmjs.com/package/js-queue)\n[![npm downloads](https://img.shields.io/npm/dm/js-queue.svg)](https://www.npmjs.com/package/js-queue)\n[![license](https://img.shields.io/github/license/RIAEvangelist/js-queue.svg)](./licence.md)\n\n## Install\n\n```sh\nnpm install js-queue\n```\n\nNative ES modules:\n\n```js\nimport Queue from 'js-queue';\n\nconst queue=new Queue;\n\nqueue.add(\n    function(){\n        console.log('first');\n        this.next();\n    },\n    function(){\n        console.log('second');\n        this.next();\n    }\n);\n```\n\nCommonJS remains supported:\n\n```js\nconst Queue=require('js-queue');\n```\n\n## Browser ESM: bundler or no bundler\n\n`js-queue` works with bundlers and without a bundler. Bundlers resolve the bare package imports normally. Native browser ESM uses a standard import map and runs the same JavaScript directly, with no build or transpilation step.\n\nFor a normal npm layout where `easy-stack` is hoisted, place this complete import map before the module script:\n\n```html\n<script type=\"importmap\">\n{\n  \"imports\": {\n    \"js-queue\": \"./node_modules/js-queue/queue.js\",\n    \"js-queue/\": \"./node_modules/js-queue/\",\n    \"js-queue/stack\": \"./node_modules/js-queue/stack.js\",\n    \"js-queue/stack.js\": \"./node_modules/js-queue/stack.js\",\n    \"easy-stack\": \"./node_modules/easy-stack/stack.js\"\n  }\n}\n</script>\n<script type=\"module\">\n  import Queue from 'js-queue';\n  import Stack from 'js-queue/stack';\n\n  const queue=new Queue;\n  const stack=new Stack;\n</script>\n```\n\nIf npm nests `easy-stack` because the application installs a conflicting root version, use this complete scoped map instead. Its scope preserves the dependency boundary that Node and bundlers apply to imports originating inside `js-queue`:\n\n```html\n<script type=\"importmap\">\n{\n  \"imports\": {\n    \"js-queue\": \"./node_modules/js-queue/queue.js\",\n    \"js-queue/\": \"./node_modules/js-queue/\",\n    \"js-queue/stack\": \"./node_modules/js-queue/stack.js\",\n    \"js-queue/stack.js\": \"./node_modules/js-queue/stack.js\",\n    \"easy-stack\": \"./node_modules/easy-stack/stack.js\"\n  },\n  \"scopes\": {\n    \"./node_modules/js-queue/\": {\n      \"easy-stack\": \"./node_modules/js-queue/node_modules/easy-stack/stack.js\"\n    }\n  }\n}\n</script>\n<script type=\"module\">\n  import Stack from 'js-queue/stack';\n\n  const stack=new Stack;\n</script>\n```\n\nEvery import-map URL is relative to the HTML document. Serve the application over HTTP(S), and configure that server to expose the mapped `node_modules` files. `file://` is not a supported loading path. See the [browser guide](https://riaevangelist.github.io/js-queue/browser/) for the classic-script option and live no-bundler examples.\n\n## The flow contract\n\n`js-queue` does not guess when a task is complete. A task releases the next item by calling `this.next()`—immediately, from a callback, or after an awaited operation.\n\n```js\nqueue.add(function(){\n    fetch('/work')\n        .then(handleResponse)\n        .finally(()=>this.next());\n});\n```\n\nThat explicit hand-off makes the same queue useful for synchronous steps, callback APIs, network work, connection gates, and manually controlled pipelines.\n\n## Performance\n\n**The fastest js-queue yet. Install it. Don’t rebuild it.**\n\n![Constructing 100,000 queues: js-queue 3.1.0 is 19.86 times faster than 3.0.0](./assets/benchmark-construct.svg)\n\n![Scheduling and draining 100,000 tasks: js-queue 3.1.0 is 1.41 times faster than 3.0.0](./assets/benchmark-tasks.svg)\n\nNode 24.18, 100,000 operations, median of 21 alternating samples. [Method and results](https://riaevangelist.github.io/js-queue/performance/). CI reruns the tagged comparison.\n\n## Public surface\n\n| Member | Type | Purpose |\n| --- | --- | --- |\n| `add(...tasks)` | method | Validate and append functions; auto-start when idle. |\n| `next()` | method | Run the next FIFO task when the queue is not stopped. |\n| `clear()` | method | Remove pending tasks and return the new empty array. |\n| `contents` | getter/setter | Read or replace the pending function array. |\n| `size` | getter | Number of pending tasks. |\n| `running` | getter | Whether a task currently owns the queue. |\n| `autoRun` | boolean | Start automatically after `add()`; defaults to `true`. |\n| `stop` | boolean | Hold execution without discarding pending work. |\n\nEvery task receives the queue as `this`. Invalid tasks are rejected before any item from the same `add()` call is appended. If a task throws synchronously, the queue returns to an idle, recoverable state and preserves the remaining work.\n\n## Entry points\n\n| Import | Format | Use |\n| --- | --- | --- |\n| `js-queue` | ESM or CommonJS | Conditional primary entry. |\n| `js-queue/queue.js` | ESM or CommonJS | Compatibility path to the queue. |\n| `js-queue/queue-vanilla.js` | classic browser script | Publishes `globalThis.Queue`. |\n| `js-queue/stack` | ESM or CommonJS | The modernized `easy-stack` 2.1 LIFO entry. |\n\nThe runtime supports Node.js 22.13 and newer. Native ESM and CommonJS both load the same synchronous source files; no duplicate Node build is shipped.\n\n## Test and coverage evidence\n\n**Tested with [vanilla-test](https://riaevangelist.github.io/vanilla-test/).** The repository has 102 focused checks organized into five non-overlapping layers: [Unit](https://riaevangelist.github.io/js-queue/testing/unit/), [Functional](https://riaevangelist.github.io/js-queue/testing/functional/), [Behavioral](https://riaevangelist.github.io/js-queue/testing/behavioral/), [Integration](https://riaevangelist.github.io/js-queue/testing/integration/), and [Regression](https://riaevangelist.github.io/js-queue/testing/regression/). Forty-two shared checks import the package by its bare name and run unchanged in Node and real Google Chrome; Chrome resolves those imports through the checked-in import-map configuration.\n\n<a href=\"https://riaevangelist.github.io/vanilla-test/\"><img src=\"./assets/vanilla-test-header.png\" width=\"520\" alt=\"vanilla-test — native JavaScript testing for Node.js and browsers\"></a>\n\n```sh\nnpm test\nnpm run test:unit\nnpm run test:functional\nnpm run test:behavioral\nnpm run test:integration\nnpm run test:regression\nnpm run test:consumer\nnpm run coverage\n```\n\nThe 10 Unit checks isolate API facts. The 30 Functional checks cover queue workflows and Playground behavior. The 9 Behavioral checks verify complete consumer outcomes across explicit hand-offs, gates, recovery policies, stale-reference isolation, independent queues, reprioritization, and native no-bundler loading. The 28 Integration checks cover interacting queue operations, package formats, a poisoned packed-consumer dependency conflict, benchmark evidence, stack compatibility, and local HTTP delivery. The 25 Regression checks protect validation, recovery, the no-WeakMap performance contract, import maps, documentation, artwork, and deployment wiring. Both native V8 collectors continue to enforce 100% statement, branch, function, and line coverage for the shipped ESM queue.\n\n[Node coverage report](https://riaevangelist.github.io/js-queue/reports/node/) · [Chrome coverage report](https://riaevangelist.github.io/js-queue/reports/chrome/)\n\n## Version 3.1\n\nVersion 3.1 replaces WeakMap lookups with private instance fields, shares one Node source between `import` and `require`, and moves the runtime floor to Node 22.13. Existing `require('js-queue')` and `require('js-queue/stack.js')` syntax remains supported on that Node floor; `queue-vanilla.js` remains available to current browsers with native private fields.\n\nRead the [migration guide](./MIGRATION.md) and [changelog](./CHANGELOG.md) before upgrading an application on Node versions older than 22.13.\n\n## License\n\n[MIT](./licence.md)\n","publish_time":1786899086101,"_cnpm_publish_time":1786899086101,"dist-tags":{"latest":"3.1.1"}}