{"id":28468567,"url":"https://github.com/cnwhy/promise-queue-plus","last_synced_at":"2025-06-25T20:30:48.439Z","repository":{"id":30891718,"uuid":"34449444","full_name":"cnwhy/promise-queue-plus","owner":"cnwhy","description":"Promise-based queue. Support timeout, retry and so on.","archived":false,"fork":false,"pushed_at":"2019-01-30T03:21:22.000Z","size":289,"stargazers_count":121,"open_issues_count":2,"forks_count":15,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-06-07T08:07:55.429Z","etag":null,"topics":["promise","promise-queue","queue"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cnwhy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-23T10:23:47.000Z","updated_at":"2024-09-17T03:22:42.000Z","dependencies_parsed_at":"2022-08-31T00:01:03.351Z","dependency_job_id":null,"html_url":"https://github.com/cnwhy/promise-queue-plus","commit_stats":null,"previous_names":["cnwhy/queue-fun"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/cnwhy/promise-queue-plus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fpromise-queue-plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fpromise-queue-plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fpromise-queue-plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fpromise-queue-plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cnwhy","download_url":"https://codeload.github.com/cnwhy/promise-queue-plus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Fpromise-queue-plus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261948748,"owners_count":23234883,"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":["promise","promise-queue","queue"],"created_at":"2025-06-07T08:07:58.176Z","updated_at":"2025-06-25T20:30:48.427Z","avatar_url":"https://github.com/cnwhy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Promise Queue +  \n[![NPM version][npm-image]][npm-url]\n[![npm download][download-image]][npm-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![Build Status][BuildStatus-image]][BuildStatus-url]\n\nPromise-based queue. Support timeout, retry and so on.  \n\n## demo\n``` javascript\nvar Queue = require('promise-queue-plus');\nvar q = Queue.Promise; //a Promise utils;\n\n//Realize a queue with a maximum concurrency of 1\nvar queue1 = Queue(1,{\n        \"retry\":0               //Number of retries\n        ,\"retryIsJump\":false     //retry now? \n        ,\"timeout\":0            //The timeout period\n    });\n\n//a return promise function\nfunction testfn(i){\n    return new Promise(function(resolve,reject){\n        setTimeout(function(){\n            resolve(i)\n        },300)\n    })\n}\nvar log = function(msg){ console.log(msg); }\n\nqueue1.push(testfn,[1]) //add job (FIFO)\n.then(log); \n\nqueue1.push(function(){return 2;}) //The normal function returns a promise according to the Promise / A + rule\n.then(log);\n\nqueue1.unshift(testfn,[0]) //add job (LIFO)\n.then(log);\n\nqueue1.addLikeArray([3,4],testfn,{'workResolve':log}) //Add multiple jobs with Array, Work done will execute 'workResolve'\n.then(log) \n\nqueue1.addLikeProps({'a':5,'b':6,'c':7},testfn,{'workResolve':log}) //Add multiple jobs with Map,\n.then(log)\n\nqueue1.add(function(resolve,reject){\n    resolve(8);\n}).then(log)\n\n//queue1.start(); //queue start;\nqueue1.go(testfn,['go']).then(log) \n/*\n Equivalent to:\n    queue1.push(testfn,['go']).then(console.log);\n    queue1.start(); \n* In general, it is convenient to use the 'go'\n*/\n\n// Output:\n/* \n0\n1\n2\n3\n4\n[ 3, 4 ]\n5\n6\n7\n{ a: 5, b: 6, c: 7 }\n8\ngo\n*/\n```\n\n## API \n\n### new Queue(maxConcurrent,*options*)\nCreates a queue;\n- `maxConcurrent` MaxNumber Concurrent\n\nabout options like:\n```js\nvar Queue = require(\"promise-queue-plus\");\nvar queue = Queue(10,{\n        \"queueStart\":function(queue){}         \n        ,\"queueEnd\":function(queue){}          \n        ,\"workAdd\":function(item,queue){}     \n        ,\"workResolve\":function(value,queue){} \n        ,\"workReject\":function(reason,queue){} \n        ,\"workFinally\":function(queue){}       \n        ,\"retry\":3                                    \n        ,\"retryIsJump\":true                           \n        ,\"timeout\":2000            \n        ,\"autoRun\":true               \n    })\n```\n\n### Queue.Q / Queue.Promise\na Promise utils, See also [extend-promise#类扩展](https://github.com/cnwhy/extend-promise#类扩展)  \nNote: The prototype is not expanded with [extend-promise][github-extend-promise];\n\n### Queue.use(Promise) , Queue.createUse(Promise)\nModify the internal use of Promise , the default use of [bluebird][github-bluebird]    \n- `Queue.use(Promise)` use `Promise`;  \n- `Queue.createUse(Promise)` return new Class use `Promise`;  \n\n```javascript\nvar Queue = require(\"promise-queue-plus\") //default use of bluebird\nQueue.Promise.defer().promise instanceof Promise; //false\n//use ES6 Promise\nQueue.use(Promise);  \nQueue.Promise.defer().promise instanceof Promise; //true\nvar queue1 = Queue(1);\nqueue1.push(function(){}) instanceof Promise; //true;\n\n//Create a new class `NQueue`, does not affect the original` Queue`;\nvar NQueue = Queue.createUse(require(\"q\")); //use q module\n\n//use create function (v1.2+)\nvar Queue = require(\"promise-queue-plus/create\")(Promise);\n\n```\n\n  \n### queue.push(promisefun, *args[]*, *options*)  \nadd job (FIFO)\n- `promisefun` promise function\n- `args` arguments \nabout options like:\n```js\nqueue.push(function(a,b){return a+b;},[1,2],{\n    \"workResolve\":false                    //1. Queue events are not executed\n    ,\"workReject\":function(reason,queue){} //2. Are executed\n    ,\"workFinally\":function(queue){return false;} //3. if return false,Queue events are not executed\n    ,\"retry\":0                                 //Override the queue settings\n    ,\"retryIsJump\":false                        //Override the queue settings\n    ,\"timeout\":0                               //Override the queue settings\n});\n```\n\n\n### queue.unshift(promisefun, *args[]*, *options*)\nadd job (LIFO)  \n\n### queue.go(promisefun, *args[]*, *options*)  \nlike `push` and start queue  \n\n### queue.jump(promisefun, *args[]*, *options*)  \nlike `unshift` and start queue  \n\n### queue.add(executor, *options*, *start*, *jump*)  \n- `executor` like the `new Promise(executor)`\n- `options` like 'options' for `push` \n- `start` Whether to start immediately\n- `jump`  Whether the LIFO mode\n\n```js\nqueue.add(function(resolve, reject){\n    resolve(1);\n},true).then(console.log,console.error)\n//output 1;\n```\n\n### queue.addArray(arr,*start*,*jump*)  \nAdd multiple jobs with Array, promise value as Array;\n- `arr`   arguments Array\n- `start` Whether to start immediately\n- `jump`  Whether the LIFO mode\n\n```js\nqueue.addArray([\n    [function(a){return a},[1],{}],\n    [function(a,b){return a+b;},[1,2],{}]\n],true).then(console.log,console.error);\n//output [1,3]\n```\n\n### queue.addProps(props,*start*,*jump*)  \nAdd multiple jobs with Array, promise value as Map;\n- `props` arguments Map \n- `start` Whether to start immediately\n- `jump`  Whether the LIFO mode\n\n```js\nqueue.addProps({\n    a:[function(a){return a},[1]],\n    b:[function(a,b){return a+b;},[1,2]]\n},true).then(console.log,console.error);\n//output {a:1,b:3}\n```\n\n### queue.addLikeArray(arrArgs[],promisefun,*options*,*start*,*jump*)  \nSyntax for 'addArray' sugar \n\n```js\nfunction addfn(){\n    var i = 0,sum;\n    while(i\u003carguments.length){\n        sum = i == 0 ? arguments[i] : sum + arguments[i];\n    }\n    return sum;\n}\nqueue.addLikeArray([1,[1,2]],addfn,true).then(console.log,console.error);\n//output [1,3]\n```\n\n### queue.addLikeArrayEach (arrArgs[],promisefun,*options*,*start*,*jump*)\nlike `queue.addLikeArray`,To \"promisefun\" pass parameters similar to \"forEach\" (element, index, arrArgs)\n\n```js\nfunction fn(v,i,arr){\n    return i + \" : \" + v;\n}\nqueue.addLikeArrayEach([1,[1,2]],fn,true).then(console.log,console.error);\n//output [ '0 : 1', '1 : 1,2' ]\n```\n\n### queue.addLikeProps (props,promisefun,*options*,*start*,*jump*)  \nSyntax for 'addProps' sugar \n\n### queue.addLikePropsEach (props,promisefun,*options*,*start*,*jump*)\nlike `queue.addLikeProps`,To \"promisefun\" pass parameters similar to \"forEach\" (value, key, props)\n\n### queue.start()\nstart queue;\n\n### queue.stop()\nstop queue;\n\n### queue.clear(reason)  \nclear queue,The rest of the queue will be rejected with `reason`;\n\n### queue.option(name, *value*)  \nSet/Get queue `options`\n\n### queue.getMax()\nGet MaxNumber Concurrent;\n\n### queue.setMax(newMax)\nSet MaxNumber Concurrent;\n\n### queue.getLength() \nQueue remaining job count;\n\n### queue.getRunCount()\nQueue running job count;\n\n### queue.isStart()\n\n### queue.onError = function(err){}\nQueue other error handling\n\n## About the browser  \nBecause `bluebird` too big, Of browsers use [easy-promise][github-easy-promise] instead of [bluebird][github-bluebird];  \n- dist/promise-queue-plus.js\n- dist/promise-queue-plus.min.js (gzip 3.8k)\n\n[npm-image]: https://img.shields.io/npm/v/promise-queue-plus.svg\n[download-image]: https://img.shields.io/npm/dm/promise-queue-plus.svg\n[npm-url]: https://npmjs.org/package/promise-queue-plus\n[coveralls-image]: https://coveralls.io/repos/cnwhy/promise-queue-plus/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/r/cnwhy/promise-queue-plus?branch=master\n[BuildStatus-url]: https://travis-ci.org/cnwhy/promise-queue-plus\n[BuildStatus-image]: https://api.travis-ci.org/cnwhy/promise-queue-plus.svg\n\n[github-q]: https://github.com/kriskowal/q\n[github-bluebird]: https://github.com/petkaantonov/bluebird\n[github-easy-promise]: https://github.com/petkaantonov/bluebird\n[github-extend-promise]: https://github.com/cnwhy/extend-promise\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnwhy%2Fpromise-queue-plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcnwhy%2Fpromise-queue-plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnwhy%2Fpromise-queue-plus/lists"}