{"id":30735694,"url":"https://github.com/flarestart/wait-queue","last_synced_at":"2025-09-03T20:13:31.132Z","repository":{"id":65412495,"uuid":"79225379","full_name":"flarestart/wait-queue","owner":"flarestart","description":"WaitQueue is an async implement of Array","archived":false,"fork":false,"pushed_at":"2023-12-30T20:51:22.000Z","size":80,"stargazers_count":18,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-25T03:41:49.820Z","etag":null,"topics":["await-promises","loop-task","queue"],"latest_commit_sha":null,"homepage":"","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/flarestart.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}},"created_at":"2017-01-17T12:28:06.000Z","updated_at":"2023-09-15T06:14:15.000Z","dependencies_parsed_at":"2024-06-18T18:15:42.630Z","dependency_job_id":null,"html_url":"https://github.com/flarestart/wait-queue","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"3e347bc6b1bc45cd89a6f090e6980fb425cfdebe"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/flarestart/wait-queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarestart%2Fwait-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarestart%2Fwait-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarestart%2Fwait-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarestart%2Fwait-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flarestart","download_url":"https://codeload.github.com/flarestart/wait-queue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flarestart%2Fwait-queue/sbom","scorecard":{"id":402612,"data":{"date":"2025-08-11","repo":{"name":"github.com/flarestart/wait-queue","commit":"3e347bc6b1bc45cd89a6f090e6980fb425cfdebe"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/21 approved changesets -- score normalized to 0","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":"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":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"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":"Dangerous-Workflow","score":-1,"reason":"no workflows found","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":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"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":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"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":"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":"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":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"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 'master'"],"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 10 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"}}]},"last_synced_at":"2025-08-18T20:25:18.546Z","repository_id":65412495,"created_at":"2025-08-18T20:25:18.547Z","updated_at":"2025-08-18T20:25:18.547Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273502352,"owners_count":25117173,"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-09-03T02:00:09.631Z","response_time":76,"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":["await-promises","loop-task","queue"],"created_at":"2025-09-03T20:13:22.502Z","updated_at":"2025-09-03T20:13:31.097Z","avatar_url":"https://github.com/flarestart.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wait-queue\n\n[![Travis CI][ci-image]][ci-url]\n[![Coveralls][coverage-image]][coverage-url]\n[![NPM version][npm-image]][npm-url]\n[![Downloads][downloads-image]][downloads-url]\n\nA javascript wait queue object handle infinity loop tasks more efficiently\n\nWaitQueue is an async implements of Array\n\n## Table of Contents\n\n- [How to use](#how-to-use)\n- [Requirements](#requirements)\n- [Change Log](./CHANGELOG.md)\n- [Properties](#properties)\n- [Methods](#methods)\n- [Benchmark](#benchmark)\n\nExamples\n\n- [Iterator](#iterator)\n- [Multi Worker](#example-multi-worker)\n- [Push a function](#example-push-a-function)\n- [Loop Tasks](#example-loop-tasks)\n- [Using with co](#using-with-co)\n\n## How to use\n\n```shell\n$ npm install wait-queue\n```\n\n### TypeScript\n\n```typescript\nimport WaitQueue from 'wait-queue';\nconst wq = new WaitQueue\u003cstring\u003e();\n\nasync function run() {\n  const item = await wq.shift();\n  console.log(item);\n}\n\nsetTimeout(() =\u003e {\n  wq.push('foo');\n}, 1000);\n\nrun();\n```\n\n### JS\n\n```js\nconst WaitQueue = require('wait-queue');\nconst wq = new WaitQueue();\nwq.shift().then(function(item) {\n  // will wait until got value\n  console.log(item);\n  // \"foo\"\n});\n\nsetTimeout(function() {\n  wq.push('foo');\n}, 1000);\n```\n\n## Requirements\n\n**Build**: Node.js \u003e= 8.x\n\n## Properties\n\n### wq.length\n\nLength of the WaitQueue(readonly)\n\n### wq.queue\n\nA LinkedList, used to store the queue items, Do not modify it directly\n\n### wq.listeners\n\nIf no elements in queue yet, listener will add here, Don't modify it\n\n## Methods\n\n### wq.push(item1, [item2])\n\nAdd items to the end of the queue, will return length of the queue\n\n### wq.shift().then( item =\u003e )\n\nGot an item from front of the queue, this is a Promise method, if there's no item\nin the queue, it will wait\n\n### wq.unshift(item)\n\nPut an item in front of the queue, will return length of the queue\n\n### wq.pop().then( item =\u003e )\n\nGot an item at the end of the queue, this is a Promise method, if there's no item\nin the queue, it will wait\n\n### wq.empty() alias of wq.clearQueue()\n\nClear the queue, Won't clear listeners\n\n### wq.clearListeners()\n\nClear waited listeners of the queue\n\n## Benchmark\n\n```\n$ git clone https://github.com/flarestart/wait-queue.git\n$ cd wait-queue\n$ npm install\n$ npm run benchmark\n```\n\nSample data in Macbook Pro MF839/8GB\n\n### 1.1.0(Improve benchmark code)\n\n    Array.push(1k data) speed test x 629,538 ops/sec ±22.90% (26 runs sampled)\n    Array.push(1k data) 1000000 times then Array.shift() speed test x 492 ops/sec ±1.02% (89 runs sampled)\n    WaitQueue.push(1k data) speed test x 501,581 ops/sec ±23.45% (14 runs sampled)\n    WaitQueue.unshift(1k data) speed test x 447,272 ops/sec ±24.80% (14 runs sampled)\n    WaitQueue.shift() speed test x 315,356 ops/sec ±14.30% (52 runs sampled)\n    WaitQueue.pop() speed test x 240,568 ops/sec ±51.35% (39 runs sampled)\n    WaitQueue.push(1k data) 1000000 times then WaitQueue.shift() speed test x 476,918 ops/sec ±26.68% (29 runs sampled)\n    WaitQueue.push(1k data) 1000000 times then WaitQueue.pop() speed test x 471,668 ops/sec ±25.08% (31 runs sampled)\n    Array.push(4k data) speed test x 119,981 ops/sec ±61.52% (14 runs sampled)\n    Array.push(4k data) 1000000 times then Array.shift() speed test x 479 ops/sec ±1.41% (86 runs sampled)\n    WaitQueue.push(4k data) speed test x 147,153 ops/sec ±46.03% (14 runs sampled)\n    WaitQueue.unshift(4k data) speed test x 157,694 ops/sec ±37.29% (16 runs sampled)\n    WaitQueue.push(4k data) 1000000 times then WaitQueue.shift() speed test x 447,783 ops/sec ±28.01% (31 runs sampled)\n    WaitQueue.push(4k data) 1000000 times then WaitQueue.pop() speed test x 409,826 ops/sec ±30.73% (28 runs sampled)\n\n### 1.0.3(Use LinkedList)\n\n    .push() 1k data speed test x 511,367 ops/sec ±31.07% (27 runs sampled)\n    .unshift() 1k data speed test x 269,995 ops/sec ±39.60% (14 runs sampled)\n    .push() 4k data speed test x 41,531 ops/sec ±12.20% (7 runs sampled)\n    .unshift() 4k data speed test x 35,928 ops/sec ±5.11% (8 runs sampled)\n    .shift() 69614.33093950555 /s\n\n### 1.0.2(Use Array)\n\n    .push() 1k data speed test x 554,552 ops/sec ±26.09% (25 runs sampled)\n    .unshift() 1k data speed test x 132 ops/sec ±2.96% (72 runs sampled)\n    .push() 4k data speed test x 75,107 ops/sec ±22.32% (9 runs sampled)\n    .unshift() 4k data speed test x 115 ops/sec ±2.15% (71 runs sampled)\n    .shift() `wait too long, I didn't wait for the result, I guess is about 110/s`\n\n## Example: Iterator\n\nuse for ... of to get all values\n\n```js\n'use strict';\nconst WaitQueue = require('wait-queue');\nconst wq = new WaitQueue();\n\nwq.push(1, 2, 3, 4, 5);\n\nconsole.log('length', wq.length);\nfor (var n of wq) {\n  console.log(n);\n}\n```\n\n## Example: Multi Worker\n\n```js\n'use strict';\nconst WaitQueue = require('wait-queue');\nconst wq = new WaitQueue();\n\n// worker loop\nfunction run_worker(id, time) {\n  var loop = function() {\n    // get item at the front of the queue\n    wq.shift().then(item =\u003e {\n      console.log('worker-' + id);\n      console.log('  queue-len', wq.queue.length, 'item', item);\n      setTimeout(loop, time);\n    });\n  };\n  loop();\n}\n\n// worker-a use 1s every task\nrun_worker('a', 1000);\n// worker-b use 2s every task\nrun_worker('b', 2000);\n// worker-c use 5s every task\nrun_worker('c', 5000);\n\n// add a task every 500ms\nfor (var n = 0; n \u003c 20; n++) {\n  wq.push(n);\n}\n```\n\n## Example: Push a function\n\n```js\n'use strict';\nconst WaitQueue = require('wait-queue');\nconst wq = new WaitQueue();\n\n// there's no task here\nwq.shift().then(item =\u003e {\n  item.call();\n});\n\n// add a function as item\nwq.push(function() {\n  console.log('a function');\n});\n```\n\n## Example: Loop Tasks\n\n```js\n'use strict';\nconst WaitQueue = require('wait-queue');\nconst wq = new WaitQueue();\n\nfunction loop() {\n  // put first element out of queue\n  wq.shift()\n    .then(function(item) {\n      // do some job on item\n      console.log(item);\n      // do next loop\n      setImmediate(loop);\n    })\n    .catch(function(e) {\n      console.error('error', e);\n      setImmediate(loop);\n    });\n}\nsetImmediate(loop);\n\nvar taskID = 0;\nvar interval;\n// add a task every 1s\ninterval = setInterval(function() {\n  wq.push({\n    taskid: taskID++,\n  });\n}, 1000);\n```\n\n## Using with co\n\n```js\n'use strict';\nconst WaitQueue = require('wait-queue');\nconst co = require('co');\nconst wq = new WaitQueue();\n\nco(function*() {\n  while (true) {\n    let item = yield wq.shift();\n    // catch errors from runTask, so that it won't stop the task loop\n    try {\n      yield runTask(item);\n    } catch (e) {\n      // output errors\n      console.error('error', item);\n      // you can re do task from here\n      wq.push(item);\n      console.log('add error item to end of queue');\n    }\n  }\n});\n\nfunction runTask(item) {\n  return new Promise(function(resolve, reject) {\n    // a task will run 2s\n    setTimeout(function() {\n      if (Math.random() \u003e 0.8) {\n        return reject(new Error('some unknown error'));\n      }\n      console.log('done', item);\n      resolve();\n    }, 1000);\n  });\n}\n\n// add a task every 1s\nvar taskID = 0;\nsetInterval(function() {\n  wq.push({\n    taskid: taskID++,\n  });\n}, 1000);\n```\n\n## License\n\nMIT\n\n[coverage-image]: https://img.shields.io/coveralls/flarestart/wait-queue.svg\n[coverage-url]: https://coveralls.io/github/flarestart/wait-queue\n[ci-image]: https://img.shields.io/travis/flarestart/wait-queue.svg?branch=master\n[ci-url]: https://travis-ci.org/flarestart/wait-queue\n[npm-image]: https://img.shields.io/npm/v/wait-queue.svg\n[npm-url]: https://npmjs.org/package/wait-queue\n[downloads-image]: http://img.shields.io/npm/dm/wait-queue.svg\n[downloads-url]: https://npmjs.org/package/wait-queue\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflarestart%2Fwait-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflarestart%2Fwait-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflarestart%2Fwait-queue/lists"}