{"_id":"parallel-task-queue","_rev":"36-29db64862ad5df6b1c3da6092dcee7b7","name":"parallel-task-queue","description":"A simple tool to keep requests to be executed in order with configurable parallelism.","dist-tags":{"latest":"2.1.2"},"versions":{"1.0.0":{"name":"parallel-task-queue","version":"1.0.0","description":"A simple tool to keep requests to be executed in order with configurable parallelism.","main":"index.js","directories":{"example":"example"},"dependencies":{"bluebird":"^3.4.6"},"devDependencies":{},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["task","queue","concurrency","parallelism","async"],"author":{"name":"sidson_aidson"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/sidsonAidson/parallel-task-queue.git"},"contributors":[{"name":"* Moussa Ndour","email":"moussa_ndour@hotmail.fr"}],"gitHead":"47f8a329ca0cc44e8a503219e26d12873b60b757","bugs":{"url":"https://github.com/sidsonAidson/parallel-task-queue/issues"},"homepage":"https://github.com/sidsonAidson/parallel-task-queue#readme","_id":"parallel-task-queue@1.0.0","_shasum":"5cad8e9180d57a38d0515918b84896f99a2e6de7","_from":".","_npmVersion":"3.10.7","_nodeVersion":"6.3.1","_npmUser":{"name":"ys_sidson_aidson","email":"moussa_ndour@hotmail.fr"},"dist":{"shasum":"5cad8e9180d57a38d0515918b84896f99a2e6de7","tarball":"https://registry.npmjs.org/parallel-task-queue/-/parallel-task-queue-1.0.0.tgz","integrity":"sha512-0qNGaCxeOnVGPQeifihjhZ4t2i6vd4ZDUa+6tpE5BqUpY9Q75DAW/mzPv2OOSMMYGF5Ao6OO9es4MzsD3PFB+A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICeYvUT2Jc+v2kjY3p3hBLEtfAGHVaw+GbI5k2VEXcHIAiEAlxFFerG8KK8Na4ERXwWezT0Wl0zGjTXFivu70yTfeaM="}]},"maintainers":[{"name":"ys_sidson_aidson","email":"moussa_ndour@hotmail.fr"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/parallel-task-queue-1.0.0.tgz_1480089436345_0.1984156861435622"}},"2.1.0":{"name":"parallel-task-queue","description":"A simple tool to keep requests to be executed in order with configurable parallelism.","main":"index.js","directories":{"example":"example"},"dependencies":{"bluebird":"^3.4.6","node-wget":"^0.4.2"},"devDependencies":{},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["task","queue","concurrency","parallelism","async"],"author":{"name":"sidson_aidson"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/sidsonAidson/parallel-task-queue.git"},"version":"2.1.0","contributors":[{"name":"* Moussa Ndour","email":"moussa_ndour@hotmail.fr"}],"gitHead":"95bda6009279b4487bc8d6e48d1ca639b28744e5","bugs":{"url":"https://github.com/sidsonAidson/parallel-task-queue/issues"},"homepage":"https://github.com/sidsonAidson/parallel-task-queue#readme","_id":"parallel-task-queue@2.1.0","_npmVersion":"5.3.0","_nodeVersion":"8.1.3","_npmUser":{"name":"ys_sidson_aidson","email":"moussa_ndour@hotmail.fr"},"dist":{"integrity":"sha512-op4R5KKrJrHKOrRCqybE3Ib51lVropXgVZDuQ75+CKfE/NaFYC5idKTWeXTWXi7XTyH+uVnoHDSzhYhYkQiF2g==","shasum":"4d2550bf6e208ea059c58d4a2a22997805d9712b","tarball":"https://registry.npmjs.org/parallel-task-queue/-/parallel-task-queue-2.1.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBf7M2f87Q5RSidf2sDf/MKvU2Q/zOh8vUHnbQLRIXOxAiEAqTx5RRx6Y8j7rG1OWT+LDTwBvsimchmvhP36a1mtPnk="}]},"maintainers":[{"name":"ys_sidson_aidson","email":"moussa_ndour@hotmail.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parallel-task-queue-2.1.0.tgz_1503090474411_0.518907065037638"}},"2.1.1":{"name":"parallel-task-queue","description":"A simple tool to keep requests to be executed in order with configurable parallelism.","main":"index.js","directories":{"example":"example"},"dependencies":{"bluebird":"^3.4.6","node-wget":"^0.4.2"},"devDependencies":{},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["task","queue","concurrency","parallelism","async"],"author":{"name":"sidson_aidson"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/sidsonAidson/parallel-task-queue.git"},"version":"2.1.1","contributors":[{"name":"* Moussa Ndour","email":"moussa_ndour@hotmail.fr"}],"gitHead":"d03a583c94e48e54060ff6f3abd62221c0b8fdb4","bugs":{"url":"https://github.com/sidsonAidson/parallel-task-queue/issues"},"homepage":"https://github.com/sidsonAidson/parallel-task-queue#readme","_id":"parallel-task-queue@2.1.1","_npmVersion":"5.3.0","_nodeVersion":"8.1.3","_npmUser":{"name":"ys_sidson_aidson","email":"moussa_ndour@hotmail.fr"},"dist":{"integrity":"sha512-pIzUnepULC5d/T9p0yk67w3pyL91GCsEok8hZzMMVH9U9chIfaj5CfL2DQdX+ZnnckxNhOlUUU4NX3iXpkg4JQ==","shasum":"9167aa867fcd9b9a9f77b14b3c45b397db2b1ea8","tarball":"https://registry.npmjs.org/parallel-task-queue/-/parallel-task-queue-2.1.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCOhWtlna63gqi30JCOY4dTi6IELd7c0DQg5BAmeO9tBgIhANa6DG5yN+tkcSgc0guO9u4ID8ht/9zT6QZYyJKjqamR"}]},"maintainers":[{"name":"ys_sidson_aidson","email":"moussa_ndour@hotmail.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parallel-task-queue-2.1.1.tgz_1504271770843_0.9907007748261094"}},"2.1.2":{"name":"parallel-task-queue","description":"A simple tool to keep requests to be executed in order with configurable parallelism.","main":"index.js","directories":{"example":"example"},"dependencies":{"bluebird":"^3.4.6","node-wget":"^0.4.2"},"devDependencies":{},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["task","queue","concurrency","parallelism","async"],"author":{"name":"sidson_aidson"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/sidsonAidson/parallel-task-queue.git"},"version":"2.1.2","contributors":[{"name":"* Moussa Ndour","email":"moussa_ndour@hotmail.fr"}],"gitHead":"f0c6e66666409a8cf75f8ef02385d345bd69a04e","bugs":{"url":"https://github.com/sidsonAidson/parallel-task-queue/issues"},"homepage":"https://github.com/sidsonAidson/parallel-task-queue#readme","_id":"parallel-task-queue@2.1.2","_npmVersion":"5.3.0","_nodeVersion":"8.1.3","_npmUser":{"name":"ys_sidson_aidson","email":"moussa_ndour@hotmail.fr"},"dist":{"integrity":"sha512-hQ3oHO+JsOWioAD8/v74vhiDy4v4xWaYsVWngS1x94TxUTlOqvrRWoaYW+57GcHENeEe0cy0DauxRvmCl+TPjQ==","shasum":"3d1b5d3d63c42cf61ba28b4b6441c79d01199091","tarball":"https://registry.npmjs.org/parallel-task-queue/-/parallel-task-queue-2.1.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBiVplhXeti1O6W2eON2OaX0oqNylzUznm3E4EieZUB1AiEApVl0mjbzkI6x79J1oG+ntGUSZITrSOjD147JoNSCUAU="}]},"maintainers":[{"name":"ys_sidson_aidson","email":"moussa_ndour@hotmail.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/parallel-task-queue-2.1.2.tgz_1504272723824_0.5463601443916559"}}},"readme":"parallel-task-queue - Keep request process in sequence with configurable parallelism\n=====================================================\n\nParallel-task-queue is simple tool to keep requests to be executed in order with configurable parallelism.\n\nAs we known, Node.js has an event-driven architecture capable of asynchronous I/O  and  callbacks are unordered. But sometimes we may need the requests to be processed in order.\nSeq-queue takes the responsibility to make the asynchronous, unordered processing flow into serial and ordered.\n\nParallel-task-queue is a FIFO task queue and we can push tasks as we wish, anytime(before the queue closed), anywhere(if we hold the queue instance). A task is known as a function and we can do anything in the function and just need to call `task.done(data)` (`.then` will be called) to tell the queue current task has finished success fully or `task.error(error)` (`.catch will be called).\n\n * Tags: node.js\n \n http://sidsonaidson.github.io/parallel-task-queue/\n\n##Installation\n```\nnpm install parallel-task-queue\n```\n\n##Usage\n``` javascript\nlet TaskManager = require('parallel-task-queue');\n\nlet taskQueue = new TaskManager.TaskQueue({\n    globalTimeout:1000,\n    timeBeforeClose:2000,\n    paralleleTask:1\n});\n\nfor(let i = 0; i < 50;i++)\n{\n    taskQueue.push(task => {\n        setTimeout(() => {\n            let beResolved = {\n                message:'hello'\n            };\n            task.done(beResolved);\n            // or task.error(error) to trigger promess rejection\n        }, Math.floor(Math.random() * 1000));\n    }).then(data => {\n        console.log(data.message);\n    }).catch(TaskManager.TaskTimeoutError, (e) => {\n            console.log(`Task Time out`)\n    }).catch(e => {\n        console.log(e)\n    })\n}\n\ntaskQueue.on(TaskManager.ALL_TASK_FINISHED_EVENT, () => {\n    console.log('All task finished')\n});\n\n```\n\n\n``` javascript\nlet TaskManager = require('parallel-task-queue');\n \nlet taskQueue = new TaskManager.TaskQueue({\n    globalTimeout:1000,\n    timeBeforeClose:2000,\n    paralleleTask:1\n});\n \ntaskQueue.on(TaskManager.ALL_TASK_FINISHED_EVENT, () => {\n    console.log('All task finished')\n});\n \ntaskQueue.push(task => {\n        setTimeout(() => {\n            task.done();\n        }, Math.floor(Math.random() * 1000));\n    }).then(() => {\n        console.log(`Task ${i} finished`);\n    }).catch(TaskManager.TaskTimeoutError, (e) => {\n            console.log(`Task Time out`)\n    }).catch(e => {\n        console.log(e)\n    })\n \nfor(let i = 0; i < 50;i++)\n{\n    taskQueue.push(task => {\n        setTimeout(() => {\n            task.done();\n        }, Math.floor(Math.random() * 1000));\n    }).then(() => {\n        console.log(`Task ${i} finished`);\n    }).catch(TaskManager.TaskTimeoutError, (e) => {\n            console.log(`Task Time out`)\n    }).catch(e => {\n        console.log(e)\n    })\n}\n \ntaskQueue.push(task => {\n setTimeout(() => {\n            task.done();\n   }, Math.floor(Math.random() * 1000));\n    }).then(() => {\n        console.log(`Task ${i} finished`);\n    }).catch(TaskManager.TaskTimeoutError, (e) => {\n            console.log(`Task Time out`)\n    }).catch(e => {\n        console.log(e)\n    })\n \n \n```\n\n\n##API\n###`new TaskManager.TaskQueue(opt)`\nCreate a new  instance of TaskQueue. A global timeout value in ms for the new instance can be set by `timeout` parameter or use the default timeout (3s) by no parameter.\n####Arguments\n+ `opt.globalTimeout` - A global timeout value in ms (for the new instance) before processing next task.default value is `TASK_DEFAULT_TIMEOUT`\n+ `opt.timeBeforeClose` - if no task has been pushed in this duration, queue will be closed and new added task will be ignored. Default value is `TIME_OUT_BEFORE_CLOSE_QUEUE`\n+ `opt.paralleleTask` - Number of task to be executed at same time . Defaut value is `PARALLELE_TASK`\n\n###`TaskQueue.push(fn, timeout)`\nAdd a task into the queue instance.\n####Arguments\n+ `fn(task)` - The function that describes the content of task and would be invoke by queue. `fn` takes a arguemnt task and we *must* call task.done() to tell queue current task has finished.\n+ `timeout` - If specified, it would overwrite the global timeout that set by `new TaskManager.TaskQueue` for `fn`.\n\n###`TaskQueue.close()`\nClose the queue.\n\n##Event\nSeq-queue instances extend the EventEmitter and would emit events in their life cycles.\n###`BEGIN_FIRST_TASK_EVENT`\nEmited When starting first task\n###`TASK_FINISHED_EVENT`\nEmited each time one  task finished\n###`ALL_TASK_FINISHED_EVENT`\nEmit when all task finished\n\n```\n// All constant all member of `TaskManager` object\n\ttaskQueue.on(TaskManager.ALL_TASK_FINISHED_EVENT, () => {\n\t    console.log('All task finished')\n\t});\n```\n\n##Status\nTaskQueue has many life cycle with these value:\n###`TASK_NOT_START_YET_STATUS`\n### `TASK_RUNNING_STATUS`\n### `TASK_FINSHED_STATUS`\n\n## Getter\n\n\n``` javascript\n\n    get globalTimeout() {\n        \n    },\n    get taskQueue() {\n        \n    },\n    get alreadyFinishedTask() {\n       \n    },\n    get timeoutedTask(){\n        \n    },\n    get status() {\n        \n    },\n    get begined() {\n        \n    },\n    get allFinished() {\n        \n    },\n    get closed() {\n        \n    },\n    get parallelTask() {\n        \n    },\n    get runningTaskLengh() {\n        \n    },\n    get timeBeforeClose() {\n        \n    },\n    get timeoutId() {\n        \n    }\n\n```\n\n\n##Full Example\n\n```javascript\nlet TaskManager = require('../lib/parallel-task-queue');\n\nlet uuid = TaskManager.uuid;\n\n\nlet taskQueue = new TaskManager.TaskQueue({\n    globalTimeout:3000,\n    timeBeforeClose:2000,\n    paralleleTask:50\n});\n\n\nlet repeat = (value, len) => {\n    if (len == 0) return [];\n    var a = [value];\n    while (a.length * 2 <= len) a = a.concat(a);\n    if (a.length < len) a = a.concat(a.slice(0, len - a.length));\n    return a;\n};\n\nlet imgList = repeat('http://placehold.it/500x500', 30000);\nlet wget = require('node-wget');\nlet dw = 0;\n\nfor(let i = 0; i < imgList.length;i++)\n{\n    let u = ('tmp/'+uuid()+'.jpg').replace(/-/g,'');\n    taskQueue.push((task) => {\n            wget({\n                    url:  imgList[i],\n                    dest: u,      // destination path or path with filenname, default is ./\n                    timeout: 50000       // duration to wait for request fulfillment in milliseconds, default is 2 seconds\n                },\n                function (error, response, body) {\n                    //throw new TypeError('Coucou', \"unFichier.js\", 10);\n\n                    task.done();\n\n                    dw++;\n                    if (error) {\n                        console.log(`timeout ${u} ${dw}`);\n                    } else {\n                        console.log(`save ${u} ${dw} ${taskQueue.runningTaskLengh}`);\n                    }\n                }\n            );\n        }, 20000)\n        .then(() => {\n            console.log('finish');\n        })\n        .catch(TaskManager.TaskTimeoutError, (e) => {\n            console.log('Task Timeout')\n        })\n        .catch(e => {\n            console.log(e)\n        });\n}\n\ntaskQueue.on(TaskManager.ALL_TASK_FINISHED_EVENT, () => {\n    console.log('All task finished')\n});\n```","maintainers":[{"email":"moussa_ndour@hotmail.fr","name":"touskar"}],"time":{"modified":"2022-06-23T09:46:19.069Z","created":"2016-11-25T15:57:18.467Z","1.0.0":"2016-11-25T15:57:18.467Z","1.0.1":"2016-12-03T13:45:25.089Z","1.0.2":"2016-12-03T13:47:53.155Z","1.0.3":"2016-12-03T14:00:41.071Z","1.0.4":"2016-12-03T14:01:37.508Z","1.0.5":"2016-12-03T14:10:18.383Z","1.0.6":"2017-01-30T01:02:58.928Z","1.0.7":"2017-01-30T17:36:31.337Z","1.2.0":"2017-07-10T17:44:01.741Z","1.2.1":"2017-07-10T17:45:25.182Z","1.2.2":"2017-07-10T17:47:23.614Z","1.2.3":"2017-07-25T15:11:43.761Z","1.2.4":"2017-07-26T14:08:59.219Z","1.2.6":"2017-07-29T02:09:42.225Z","2.1.0":"2017-08-18T21:07:55.530Z","2.1.1":"2017-09-01T13:16:11.850Z","2.1.2":"2017-09-01T13:32:04.795Z"},"homepage":"https://github.com/sidsonAidson/parallel-task-queue#readme","keywords":["task","queue","concurrency","parallelism","async"],"repository":{"type":"git","url":"git+https://github.com/sidsonAidson/parallel-task-queue.git"},"contributors":[{"name":"* Moussa Ndour","email":"moussa_ndour@hotmail.fr"}],"author":{"name":"sidson_aidson"},"bugs":{"url":"https://github.com/sidsonAidson/parallel-task-queue/issues"},"license":"ISC","readmeFilename":"README.md","users":{"ys_sidson_aidson":true,"touskar":true}}