{"id":18576663,"url":"https://github.com/mmomtchev/queue","last_synced_at":"2025-10-07T13:20:30.153Z","repository":{"id":37075717,"uuid":"234622124","full_name":"mmomtchev/Queue","owner":"mmomtchev","description":"async/await-compatible Promise-based priority queues","archived":false,"fork":false,"pushed_at":"2025-10-01T08:09:52.000Z","size":2189,"stargazers_count":65,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-01T10:12:15.908Z","etag":null,"topics":["async","priority-queues","promises"],"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/mmomtchev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2020-01-17T19:31:41.000Z","updated_at":"2025-10-01T08:09:50.000Z","dependencies_parsed_at":"2023-02-14T06:45:44.761Z","dependency_job_id":"f2aa7f9f-8bce-4486-b5be-3dded4b7e1ed","html_url":"https://github.com/mmomtchev/Queue","commit_stats":{"total_commits":150,"total_committers":3,"mean_commits":50.0,"dds":0.2866666666666666,"last_synced_commit":"e3e1c9e13dcbce4cd3121e0f190009ac5128a98e"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/mmomtchev/Queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmomtchev%2FQueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmomtchev%2FQueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmomtchev%2FQueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmomtchev%2FQueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmomtchev","download_url":"https://codeload.github.com/mmomtchev/Queue/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmomtchev%2FQueue/sbom","scorecard":{"id":300752,"data":{"date":"2025-08-11","repo":{"name":"github.com/mmomtchev/Queue","commit":"5adc849314e8dc33edfb1af3e1245e78cfa607e7"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.8,"checks":[{"name":"Code-Review","score":-1,"reason":"Found no human activity in the last 30 changesets","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":10,"reason":"30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/node.js.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/mmomtchev/Queue/node.js.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/mmomtchev/Queue/node.js.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/mmomtchev/Queue/node.js.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/mmomtchev/Queue/node.js.yml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   2 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":8,"reason":"2 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-xffm-g5w8-qvg7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T20:34:20.338Z","repository_id":37075717,"created_at":"2025-08-17T20:34:20.338Z","updated_at":"2025-08-17T20:34:20.338Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278780634,"owners_count":26044591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["async","priority-queues","promises"],"created_at":"2024-11-06T23:25:55.044Z","updated_at":"2025-10-07T13:20:30.116Z","avatar_url":"https://github.com/mmomtchev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-await-queue \n\n**Promise-based priority queues for throttling, rate- and concurrency limiting of Node.js or browser tasks**\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![npm version](https://img.shields.io/npm/v/async-await-queue)](https://www.npmjs.com/package/async-await-queue)\n[![Node.js CI](https://github.com/mmomtchev/Queue/workflows/Node.js%20CI/badge.svg)](https://github.com/mmomtchev/Queue/actions?query=workflow%3A%22Node.js+CI%22)\n[![codecov](https://codecov.io/gh/mmomtchev/Queue/branch/master/graph/badge.svg)](https://codecov.io/gh/mmomtchev/Queue)\n\nZero-dependency, total size: **`2.93 kB` uncompressed and `1.16 kB` gzip-compressed**\n\nThere is a medium story about using this package to parallelize download loops : [Parallelizing download loops in JS with async-await-queue](https://medium.com/@mmomtchev/parallelizing-download-loops-in-js-with-async-await-queue-670420880cd6)\n\nThis is an interesting solution to the priority queues problem.\n\nThere are other Promise-based queues out there but they are not async/await compatible and do not support priorities.\n\nIt guarantees order and never wakes up contexts that won't run.\n\nI use it with tens of thousands of jobs on the queue. _O(log(n))_ on the number of jobs, _O(log(n))_ on the number of different priorities. Just make sure to always call `Queue.end()`. Or, since 1.2, there is a safer, but less versatile method, `Queue.run()`.\n\nTypical uses:\n * Rate-limit expensive external API requests - especially on ban-happy servers\n * Avoiding to launch all the tasks in an async loop at the same time while allowing some degree of controlled concurrency\n\nThe queues keep references to the Promise `resolve()` function and resolve it from outside of the Promise constructor.\nThis is a very unusual use of Promises to implement locks that I find interesting (this is what the medium story is about).\n\n2024 Update: My technique is on track to become an official ECMAScript language: [ES Promise.withResolvers](https://tc39.es/proposal-promise-with-resolvers/)\n\n# Install\n\n`npm install --save async-await-queue`\n\n# Typical usage\n\nRequire as **CJS**\n\n```js\nconst { Queue } = require('async-await-queue');\n```\n\nImport as **ES6 Module**\n```js\nimport { Queue } from 'async-await-queue';\n```\n\n(or read the [jsdoc](https://mmomtchev.github.io/Queue/))\n\n**_IMPORTANT_** Keep in mind that when running asynchronous code without explicitly `await`ing it, you should always handle the eventual Promise rejections by a `.catch()` statement.\n\n# Examples\n\n## Basic example\n\n```js\nconst { Queue } = require('async-await-queue');\n/**\n * No more than 2 concurrent tasks with\n * at least 100ms between two tasks\n * (measured from task start to task start)\n */\nconst myq = new Queue(2, 100);\nconst myPriority = -1;\n\n/**\n * This function will launch all tasks and will\n * wait for them to be scheduled, returning\n * only when all tasks have finished\n */\nasync function downloadTheInternet() {\n  for (let site of Internet) {\n    /**\n     * The third call will wait for the previous two to complete\n     * plus the time needed to make this at least 100ms\n     * after the second call\n     * The first argument needs to be unique for every\n     * task on the queue\n     */\n    const me = Symbol();\n    /* We wait in the line here */\n    await myq.wait(me, myPriority);\n\n    /**\n     * Do your expensive async task here\n     * Queue will schedule it at\n     * no more than 2 requests running in parallel\n     * launched at least 100ms apart\n     */\n    download(site)\n      /* Signal that we are finished */\n      /* Do not forget to handle the exceptions! */\n      .catch((e) =\u003e console.error(e))\n      .finally(() =\u003e myq.end(me));\n  }\n  return await myq.flush();\n}\n```\n\n## Using a function\n\n```js\n/**\n * This is the new style API introduced in 1.2\n * It is equivalent to the previous example\n */\nasync function downloadTheInternet() {\n  const q = [];\n  for (let site of Internet) {\n     /** The third call will wait for the previous two to complete\n      * plus the time needed to make this at least 100ms\n      * after the second call\n      */\n    q.push(myq.run(() =\u003e download(site).catch((e) =\u003e console.error(e))));\n  }\n  return Promise.all(q);\n}\n```\n\n## Running sequentially\n\n```js\n/**\n * This function will execute a single task at a time\n * waiting for its place in the queue\n */\nasync function downloadTheInternet() {\n  let p;\n  /**\n   * The third call will wait for the previous two to complete\n   * plus the time needed to make this at least 100ms\n   * after the second call\n   * The first argument needs to be unique for every\n   * task on the queue\n   */\n  const me = Symbol();\n  /* We wait in the line here */\n  await myq.wait(me, myPriority);\n\n  /**\n   * Do your expensive async task here\n   * Queue will schedule it at\n   * no more than 2 requests running in parallel\n   * launched at least 100ms apart\n   */\n  try {\n    await download(site);\n  } catch (e) {\n    console.error(e);\n  } finally {\n    /* Signal that we are finished */\n    /* Do not forget to handle the exceptions! */\n    myq.end(me);\n  }\n}\n```\n\n## Fire-and-forget\n\n```js\n/**\n * This function will schedule all the tasks and\n * then will return immediately a single Promise\n * that can be awaited upon\n */\nasync function downloadTheInternet() {\n  const q = [];\n  for (let site of Internet) {\n    /**\n     * The third call will wait for the previous two to complete\n     * plus the time needed to make this at least 100ms\n     * after the second call\n     * The first argument needs to be unique for every\n     * task on the queue\n     */\n    const me = Symbol();\n    q.push(\n      myq\n        .wait(me, myPriority)\n        .then(() =\u003e download(site))\n        .catch((e) =\u003e console.error(e))\n        .finally(() =\u003e myq.end(me))\n    );\n  }\n  return Promise.all(q);\n}\n```\n\n# Unresolvable `Promise`s in Node.js\n\nWhen using this package, something that you should be aware of is that Node.js has a very particular behavior when dealing with unresolvable `Promise`s:\nhttps://github.com/nodejs/node/issues/43162\n\n**When `await`ing an unresolvable `Promise`, Node.js will simply exit - instead of blocking indefinitely - which would probably be what most people expect.**\n\nIf you are using this package in Node.js and it seems to simply unexpectedly exit without reaching the program's normal end and without reporting any errors, you most probably have an unresolvable `Promise`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmomtchev%2Fqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmomtchev%2Fqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmomtchev%2Fqueue/lists"}