{"id":15835860,"url":"https://github.com/kaelzhang/node-pending-queue","last_synced_at":"2026-04-24T16:36:32.277Z","repository":{"id":57321923,"uuid":"84286052","full_name":"kaelzhang/node-pending-queue","owner":"kaelzhang","description":"pending-queue ensures a certain asynchronous method only run once, and queues listeners which are registered to it.","archived":false,"fork":false,"pushed_at":"2017-11-27T06:00:50.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T23:16:43.168Z","etag":null,"topics":["asynchronous","nodejs","promise","queue"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-08T06:22:38.000Z","updated_at":"2017-03-09T06:43:05.000Z","dependencies_parsed_at":"2022-08-25T21:01:12.604Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/node-pending-queue","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fnode-pending-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fnode-pending-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fnode-pending-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fnode-pending-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/node-pending-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244160406,"owners_count":20408094,"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","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":["asynchronous","nodejs","promise","queue"],"created_at":"2024-10-05T14:42:10.892Z","updated_at":"2026-04-24T16:36:32.234Z","avatar_url":"https://github.com/kaelzhang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kaelzhang/node-pending-queue.svg?branch=master)](https://travis-ci.org/kaelzhang/node-pending-queue)\n\u003c!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/node-pending-queue?branch=master\u0026svg=true)](https://ci.appveyor.com/project/kaelzhang/node-pending-queue)\n--\u003e\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/pending-queue.svg)](http://badge.fury.io/js/pending-queue)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/pending-queue.svg)](https://www.npmjs.org/package/pending-queue)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/node-pending-queue.svg)](https://david-dm.org/kaelzhang/node-pending-queue)\n--\u003e\n\n# pending-queue\n\n`pending-queue` ensures a certain asynchronous method only run once, and queues listeners which are registered to it.\n\n## Install\n\n```sh\n$ npm install pending-queue --save\n```\n\n## Usage\n\n```js\nconst Queue = require('pending-queue')\n\nlet counter = 0\nconst queue = new Queue({\n  load: (a, b) =\u003e {\n    return new Promise((resolve) =\u003e {\n      counter ++\n      setTimeout(() =\u003e {\n        resolve(a + b)\n      }, 100)\n    })\n  }\n})\n\nfunction run () {\n  queue.add(1, 2).then((value) =\u003e {\n    console.log(value, counter)\n  })\n}\n\nrun()\nrun()\nrun()\n\n// 3, 1\n// 3, 1\n// 3, 1\n\n// So the load function ran only once.\n```\n\n## new Queue({load, stringify})\n\n- **load** `function(...params)` the method to get the value\n- **stringify** `function(params)=JSON.stringify` stringify the parameters as the key to queue all asynchronous requests.\n\nReturns `EventEmitter`, and `key` as the event name, so you can use `queue.listenerCount(key)` to see if there are pending tasks.\n\n## Events\n\n- **load**\n\n## .add(...params)\n\n- **params** `Arguments` which will be passed into `load`\n\nReturns `Promise`\n\n## .addWithKey(key, ...params)\n\n- **key** `String`\n\nReturn `Promise`\n\nSpecifies the key ourself, and avoid using `options.stringify` to serialize the key from `params`.\n\nBut pay attension that there should be a consistent **one-to-one** match between `key` and `params`, or make sure that you exactly know what you are doing.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fnode-pending-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Fnode-pending-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fnode-pending-queue/lists"}