{"id":13483478,"url":"https://github.com/promise-queue/promise-queue","last_synced_at":"2026-01-11T17:58:23.632Z","repository":{"id":12553994,"uuid":"15224271","full_name":"promise-queue/promise-queue","owner":"promise-queue","description":"Promise-based queue","archived":false,"fork":false,"pushed_at":"2022-09-15T17:14:18.000Z","size":43,"stargazers_count":231,"open_issues_count":10,"forks_count":34,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-05-17T08:42:23.080Z","etag":null,"topics":["javascript","promise","promise-queue","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/promise-queue.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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},"funding":{"github":"azproduction"}},"created_at":"2013-12-16T11:37:05.000Z","updated_at":"2024-01-02T05:30:14.000Z","dependencies_parsed_at":"2022-08-29T05:10:38.151Z","dependency_job_id":null,"html_url":"https://github.com/promise-queue/promise-queue","commit_stats":null,"previous_names":["azproduction/promise-queue"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/promise-queue%2Fpromise-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/promise-queue%2Fpromise-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/promise-queue%2Fpromise-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/promise-queue%2Fpromise-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/promise-queue","download_url":"https://codeload.github.com/promise-queue/promise-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245863082,"owners_count":20684785,"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":["javascript","promise","promise-queue","queue"],"created_at":"2024-07-31T17:01:11.701Z","updated_at":"2026-01-11T17:58:23.603Z","avatar_url":"https://github.com/promise-queue.png","language":"JavaScript","readme":"# promise-queue [![NPM Version](https://badge.fury.io/js/promise-queue.png)](https://npmjs.org/package/promise-queue) [![Build Status](https://travis-ci.org/azproduction/promise-queue.png?branch=master)](https://travis-ci.org/azproduction/promise-queue) [![Coverage Status](https://coveralls.io/repos/azproduction/promise-queue/badge.png?branch=master)](https://coveralls.io/r/azproduction/promise-queue)\n\nPromise-based queue\n\n## Installation\n\n`promise-queue` can be installed using `npm`:\n\n```\nnpm install promise-queue\n```\n\n## Interface\n\n - `new Queue(Number maxConcurrent, Number maxQueued): Queue`\n - `Queue#add(Function generator): Promise` - adds function argument that generates a promise to the queue\n - `Queue#getQueueLength(): Number` - returns current length of buffer(added but not started promise generators) `it \u003c= maxQueued`\n - `Queue#getPendingLength(): Number` - returns number of pending(concurrently running) promises `it \u003c= maxConcurrent`\n\n## Example\n\n### Configure queue\n\nBy default `Queue` tries to use global Promises, but you can specify your own promises.\n\n```js\nQueue.configure(require('vow').Promise);\n```\n\nOr use old-style promises approach:\n\n```js\nQueue.configure(function (handler) {\n    var dfd = $.Deferred();\n    try {\n        handler(dfd.resolve, dfd.reject, dfd.notify);\n    } catch (e) {\n        dfd.reject(e);\n    }\n    return dfd.promise();\n});\n```\n\n### Queue one by one example\n\n```js\nvar maxConcurrent = 1;\nvar maxQueue = Infinity;\nvar queue = new Queue(maxConcurrent, maxQueue);\n\napp.get('/version/:user/:repo', function (req, res, next) {\n    queue.add(function () {\n        // Assume that this action is a way too expensive\n        // Call of this function will be delayed on second request\n        return downloadTarballFromGithub(req.params);\n    })\n    .then(parseJson('package.json'))\n    .then(function (package) {\n        res.send(package.version);\n    })\n    .catch(next);\n});\n```\n\n### Getting number of pending promises and queue(buffered promises) length\n\n```js\nvar maxConcurrent = 1;\nvar maxQueue = 1;\nvar queue = new Queue(maxConcurrent, maxQueue);\n\nqueue.add(function () {\n    queue.getQueueLength() === 0;\n    queue.getPendingLength() === 1;\n    return somePromise();\n});\n\nqueue.add(function () {\n    queue.getQueueLength() === 0;\n    queue.getPendingLength() === 0;\n    return somePromise();\n});\n\nqueue.getQueueLength() === 1;\nqueue.getPendingLength() === 1;\n```\n\n[Live example](http://jsfiddle.net/RVuEU/1/)\n","funding_links":["https://github.com/sponsors/azproduction"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpromise-queue%2Fpromise-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpromise-queue%2Fpromise-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpromise-queue%2Fpromise-queue/lists"}