{"_id":"@artisnull/asyncquence","_rev":"1-0c3045a72e40bd757c111ba08f9b4cf9","name":"@artisnull/asyncquence","description":"Batch-run synchronous and asynchronous operations in sequence","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@artisnull/asyncquence","repository":{"type":"git","url":"git+https://github.com/artisnull/asyncquence.git"},"version":"0.1.0","description":"Batch-run synchronous and asynchronous operations in sequence","main":"./dist/index.js","keywords":["async","sequence","queue","task","operations","order","return"],"author":{"name":"artisnull"},"license":"MIT","gitHead":"f285b08b0c12f6548044435134c653cbbda24a84","bugs":{"url":"https://github.com/artisnull/asyncquence/issues"},"homepage":"https://github.com/artisnull/asyncquence#readme","_id":"@artisnull/asyncquence@0.1.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"artisnull","email":"lambertzachariah@gmail.com"},"dist":{"integrity":"sha512-be3N8pYbzHfXHphWFJ7Y2fldISiE84gYH/NZ3Y4/kj/eKUT1DqMHX+cTjXzyS5n7mySIveL6iN+P4wSnxoIZ5A==","shasum":"5e8354ae92384cf51f1113a3935b1835204e54e8","tarball":"https://registry.npmjs.org/@artisnull/asyncquence/-/asyncquence-0.1.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCNigxqtdf5khkkLumXf/mxr2jNwYnc9TvTaMThGb90nQIgKiwtZ3tfkyuQ2N+QDE9o3y4Bk7D4NpglWP/fSKuVpV0="}]},"maintainers":[{"name":"artisnull","email":"lambertzachariah@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/asyncquence-0.1.0.tgz_1517792183854_0.8372144137974828"}}},"readme":"asyncquence\n---\n#### Run synchronous and asynchronous functions in sequence, with hooks, value pass through, and more!\n\n---\n### Key Features\n* Executes and resolves functions in FIFO sequence, asynchronously\n* You can add to the sequence whenever you want\n* Add an array of functions, and it will be added in order into the sequence\n* Emits lifecycle events such as START, PROGRESS, or ERROR\n* Pause/Resume or Cancel whenever you want\n* Pass the results of the previous task through to the next one\n---\n### Sample usage\n##### Basic:\n```javascript\nconst asq = new Asyncquence()\n\nconst func1 = () => Promise.resolve(1)\nconst func2 = (x) => (x + 2)\n\nconst results = asq.add([\n  [func1],\n  [func2, [0]]\n])\n\nresults[0].then(console.log) // 1\nresults[1].then(console.log) // 2\n```\nAdd an array of tasks get an array of promises back in the order that we added the tasks. Pretty straightforward.  \n##### With passthrough:\n```javascript\nconst asq = new Asyncquence({\n  passPrevValue: true\n})\n\nconst func1 = () => Promise.resolve(4)\nconst func2 = (x) => (x + 10)\n\nconst results = asq.add([\n  [func1],\n  [func2]\n])\n\nresults[0].then(console.log) // 4\nresults[1].then(console.log) // 14\n```\n\n\n---\nTable of Contents\n-  \n[Reference](#reference)  \n* [config](#config)  \n* [Event](#events)  \n* [Task](#task)\n\n[API](#api)  \n* [Asyncquence](#asq)  \n* [add](#add)  \n* [addEventListener](#ael)\n* [cancel](#cancel)\n* [clear](#clear)\n* [clearEventListeners](#cel)\n* [pause](#pause)\n* [removeEventListener](#rel)\n* [resume](#resume)\n* [start](#start)\n\n---\n## Reference\n#### config  \n##### Defaults\n```javascript\nconst DEFAULT_CONFIG = {\n  execImmediate: true,\n  cancelOnError: false,\n  passPrevValue: false,\n  silent: false\n}\n```\n##### Description\n* execImmediate\n  * __true__: when first Task is added, it will be executed\n  * __false__: the start() method is called to begin execution\n* cancelOnError\n  * __true__: an error during execution will stop the rest of the sequence from completing\n  * __false__: an error during execution is reported via rejection and the error lifecycle event, but the sequence continues to the next Task\n* passPrevValue\n  * __true__: the result of the last Task is passed as the last argument to the next Task\n  * __false__: each Task is executed independently\n* silent\n  * __true__: silences default event messages\n  * __false__: default events are logged to console\n---\n#### Events\n*Not all events pass an argument to the event listener*  \nFormat: EVENT_NAME: (argument)\n\n---\n##### STATUS_CHANGE : ('READY'|'PAUSED'|'RUNNING'|'STOPPED')\n##### START\n##### PROGRESS :\n```javascript\n{\n  remaining: numRemaining // int\n  completed: numCompleted // int\n  percentComplete: percentString //String\n}\n```\n##### COMPLETE\n##### PAUSE : (nextTask)\n##### RESUME : (nextTask)\n##### CANCEL\n##### ERROR: (err)\n---\n#### Task\nThe format of function and arguments that asyncquence expects.  \nCan be one of the following:\n\n```javascript\nconst Task = [fn, [args]]\n// OR\nconst Task = {\n  method: fn,\n  args: [args]\n}\n```\n> Adding single tasks is simpler: `asq.add(fn, [args])`\n---\n\n---\n## API\n<a id='asq'></a>\n\n#### new Asyncquence([config](#config))  \nReturns new Asyncquence instance with the specified config\n```javascript\nconst asq = new Asyncquence()\n```\n---\n<a id='add'></a>\n\n#### add([Task](#task)) : Promise[]\n#### add([[Task](#task),[...Tasks]]) : Promise[]\nAdds a task(s) to the back of the queue to be executed. Returns an array of promises at indices corresponding to the index of each task added. See [Task](#task) for reference.\n\n>Triggers `'READY'` status change when adding a task to an empty queue if [config](#config) option `execImmediate:false`  \n>Triggers `START` [Event](#events) when adding a task to an empty queue if [config](#config) option `execImmediate:true`\n```javascript\n// Single task\nconst res = asq.add(Task) // res[0] has Promise for this task\n\n// Multiple tasks\nconst res = asq.add([Task1, Task2]) // res[0] for Task1, res[1] for Task2\n```\n---\n<a id='ael'></a>\n\n#### addEventListener(name:[Event](#events), callback:function)\nRegisters a function to call when the specified event takes place. See [Event](#events) for reference.\n```javascript\nasq.addEventListener('STATUS_CHANGE', cb)\n```\n---\n<a id='cancel'></a>\n\n#### cancel()\nStops execution of current [Task](#task) and empties queue. Doesn't affect event listeners\n>Triggers `CANCEL` [Event](#events)  \n>Triggers `'STOPPED'` status change\n```javascript\nasq.cancel()\n```\n---\n<a id='clear'></a>\n\n#### clear()\nImmediately empties queue and removes all event listeners, *dangerous*  \nUse `cancel()` to safely stop an asyncquence\n>Won't trigger any event listeners, as they are removed\n```javascript\nasq.clear()\n```\n---\n<a id='cel'></a>\n\n#### clearEventListeners()\nImmediately removes all event listeners\n```javascript\nasq.clearEventListeners()\n```\n---\n<a id='pause'></a>\n\n#### pause()\nPauses execution of sequence. Any currently running Tasks will complete, but no future Tasks will be executed until `resume()` is called\n>Triggers `'PAUSED'` status change  \n\n```javascript\nasq.pause()\n```\n---\n<a id='rel'></a>\n\n#### removeEventListener(name:[Event](#events), callback:function)\nRemoves the specified event listener\n```javascript\nasq.removeEventListener('STATUS_CHANGE', cb)\n```\n---\n<a id='resume'></a>\n\n#### resume()\nResumes sequence execution from a paused state.\n>Triggers `'RESUME'` status change  \n\n```javascript\nasq.resume()\n```\n---\n<a id='start'></a>\n\n#### start()\nBegins execution of the first element in the sequence. *Not applicable if [config](#config) option: `execImmediate:true`, as execution begins automatically*\n>Triggers `START` [Event](#events)  \n>Triggers `'RUNNING'` status change  \n\n```javascript\nasq.start()\n```\n---\nLICENSE\n---\nMIT License\n\nCopyright (c) 2018 artisnull\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","maintainers":[{"name":"artisnull","email":"lambertzachariah@gmail.com"}],"time":{"modified":"2022-04-04T15:39:17.793Z","created":"2018-02-05T00:56:25.281Z","0.1.0":"2018-02-05T00:56:25.281Z"},"homepage":"https://github.com/artisnull/asyncquence#readme","keywords":["async","sequence","queue","task","operations","order","return"],"repository":{"type":"git","url":"git+https://github.com/artisnull/asyncquence.git"},"author":{"name":"artisnull"},"bugs":{"url":"https://github.com/artisnull/asyncquence/issues"},"license":"MIT","readmeFilename":"readme.md"}