{"id":47605250,"url":"https://github.com/ofershap/tiny-queue","last_synced_at":"2026-04-01T19:09:48.367Z","repository":{"id":342388080,"uuid":"1173810821","full_name":"ofershap/tiny-queue","owner":"ofershap","description":"Promise queue with concurrency and priority. Drop-in p-queue replacement. ESM + CJS, zero deps, TypeScript.","archived":false,"fork":false,"pushed_at":"2026-03-26T05:25:28.000Z","size":981,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-27T01:35:25.532Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ofershap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"ofershap"}},"created_at":"2026-03-05T19:21:51.000Z","updated_at":"2026-03-26T05:25:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ofershap/tiny-queue","commit_stats":null,"previous_names":["ofershap/tiny-queue"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ofershap/tiny-queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ofershap","download_url":"https://codeload.github.com/ofershap/tiny-queue/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-queue/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291090,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-01T19:09:47.642Z","updated_at":"2026-04-01T19:09:48.357Z","avatar_url":"https://github.com/ofershap.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ofershap"],"categories":[],"sub_categories":[],"readme":"# tiny-queue\n\n[![npm version](https://img.shields.io/npm/v/tiny-pqueue.svg)](https://www.npmjs.com/package/tiny-pqueue)\n[![npm downloads](https://img.shields.io/npm/dm/tiny-pqueue.svg)](https://www.npmjs.com/package/tiny-pqueue)\n[![CI](https://github.com/ofershap/tiny-queue/actions/workflows/ci.yml/badge.svg)](https://github.com/ofershap/tiny-queue/actions/workflows/ci.yml)\n[![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nPromise queue with concurrency control. Same API as [`p-queue`](https://github.com/sindresorhus/p-queue), but ships both ESM and CJS with zero dependencies.\n\n```ts\nimport { PQueue } from \"tiny-pqueue\";\n\nconst queue = new PQueue({ concurrency: 5 });\nawait queue.add(() =\u003e fetch(url));\nawait queue.onIdle();\n```\n\n\u003e ~3.2 KB gzipped. Zero dependencies. Priority support, pause/resume, events, timeouts.\n\n![Demo](assets/demo.gif)\n\n\u003csub\u003eDemo built with \u003ca href=\"https://github.com/ofershap/remotion-readme-kit\"\u003eremotion-readme-kit\u003c/a\u003e\u003c/sub\u003e\n\n## Install\n\n```bash\nnpm install tiny-pqueue\n```\n\n## Usage\n\n```ts\nimport { PQueue } from \"tiny-pqueue\";\n\nconst queue = new PQueue({ concurrency: 3 });\n\nconst result = await queue.add(() =\u003e fetchUser(1));\nconst batch = await queue.addAll([\n  () =\u003e fetchUser(2),\n  () =\u003e fetchUser(3),\n  () =\u003e fetchUser(4),\n]);\n\nawait queue.onIdle();\n```\n\n### Priority tasks\n\n```ts\nconst queue = new PQueue({ concurrency: 1 });\n\nqueue.add(lowPriorityWork, { priority: 0 });\nqueue.add(highPriorityWork, { priority: 10 }); // runs first\n```\n\n### Pause and resume\n\n```ts\nqueue.pause();\nqueue.add(() =\u003e doWork()); // queued but won't run\n\nqueue.start(); // now it runs\nawait queue.onIdle();\n```\n\n### Timeouts\n\n```ts\nconst queue = new PQueue({\n  concurrency: 2,\n  timeout: 5000,\n  throwOnTimeout: true,\n});\n\n// throws if task takes longer than 5 seconds\nawait queue.add(() =\u003e slowOperation());\n```\n\n### Events\n\n```ts\nqueue.on(\"active\", () =\u003e console.log(`Running: ${queue.pending}`));\nqueue.on(\"idle\", () =\u003e console.log(\"All done\"));\nqueue.on(\"error\", (err) =\u003e console.error(err));\n```\n\n### Wait for queue state\n\n```ts\nawait queue.onEmpty(); // queue drained (tasks may still run)\nawait queue.onIdle(); // everything finished\nawait queue.onSizeLessThan(5); // queue drops below 5\n```\n\n## Differences from `p-queue`\n\n`p-queue` v8+ is ESM-only. If you `require(\"p-queue\")` in a CommonJS project, you get `ERR_REQUIRE_ESM`. `tiny-queue` works with both `import` and `require()`.\n\n|              | `p-queue`                    | `tiny-queue` |\n| ------------ | ---------------------------- | ------------ |\n| CJS support  | v6 only (v7+ ESM-only)       | ESM + CJS    |\n| Dependencies | `eventemitter3`, `p-timeout` | 0            |\n| TypeScript   | separate @types              | native       |\n| Export       | default                      | named        |\n\n## Migrating from p-queue\n\n```diff\n- import PQueue from \"p-queue\";\n+ import { PQueue } from \"tiny-pqueue\";\n```\n\nOne line. Everything else stays the same.\n\n## API\n\n### `new PQueue(options?)`\n\n- `concurrency` - max parallel tasks (default: `Infinity`)\n- `autoStart` - start processing immediately (default: `true`)\n- `timeout` - per-task timeout in ms\n- `throwOnTimeout` - throw on timeout instead of resolving undefined (default: `false`)\n\n### `queue.add(fn, options?)`\n\nAdd a task. Returns a promise with the result. Options: `priority` (higher = sooner, default 0), `signal` (AbortSignal).\n\n### `queue.addAll(fns, options?)`\n\nAdd multiple tasks. Returns `Promise\u003cT[]\u003e`.\n\n### `queue.pause()` / `queue.start()`\n\nPause or resume processing.\n\n### `queue.clear()`\n\nRemove all pending tasks.\n\n### `queue.onIdle()` / `queue.onEmpty()` / `queue.onSizeLessThan(n)`\n\nWait for queue state changes.\n\n### `queue.on(event, listener)` / `queue.off(event, listener)`\n\nEvents: `active`, `idle`, `add`, `next`, `completed`, `error`.\n\n### `queue.size` / `queue.pending` / `queue.isPaused` / `queue.concurrency`\n\nInspect and control the queue at runtime.\n\n## The tiny-\\* family\n\nDrop-in replacements for sindresorhus async utilities. All ship ESM + CJS with zero dependencies.\n\n| Package                                                | Replaces             | What it does                   |\n| ------------------------------------------------------ | -------------------- | ------------------------------ |\n| [tiny-limit](https://github.com/ofershap/tiny-limit)   | p-limit              | Concurrency limiter            |\n| [tiny-map](https://github.com/ofershap/tiny-map)       | p-map                | Concurrent map with order      |\n| [tiny-retry](https://github.com/ofershap/tiny-retry)   | p-retry              | Retry with exponential backoff |\n| **tiny-queue**                                         | p-queue              | Priority task queue            |\n| [tiny-ms](https://github.com/ofershap/tiny-ms)         | ms                   | Parse/format durations         |\n| [tiny-escape](https://github.com/ofershap/tiny-escape) | escape-string-regexp | Escape regex chars             |\n\nWant all async utilities in one import? Use [`tiny-pasync`](https://github.com/ofershap/tiny-async).\n\n## Author\n\n[![Made by ofershap](https://gitshow.dev/api/card/ofershap)](https://gitshow.dev/ofershap)\n\n[![LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-0A66C2?style=flat\u0026logo=linkedin\u0026logoColor=white)](https://linkedin.com/in/ofershap)\n[![GitHub](https://img.shields.io/badge/GitHub-Follow-181717?style=flat\u0026logo=github\u0026logoColor=white)](https://github.com/ofershap)\n\n---\n\nIf this saved you from `ERR_REQUIRE_ESM`, [star the repo](https://github.com/ofershap/tiny-queue) or [open an issue](https://github.com/ofershap/tiny-queue/issues) if something breaks.\n\n---\n\n\u003csub\u003eREADME built with [README Builder](https://ofershap.github.io/readme-builder/)\u003c/sub\u003e\n\n## License\n\n[MIT](LICENSE) \u0026copy; [Ofer Shapira](https://github.com/ofershap)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofershap%2Ftiny-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fofershap%2Ftiny-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofershap%2Ftiny-queue/lists"}