{"id":17715662,"url":"https://github.com/jmjuanes/keue","last_synced_at":"2025-03-31T11:23:10.607Z","repository":{"id":78714904,"uuid":"76639249","full_name":"jmjuanes/keue","owner":"jmjuanes","description":"Asynchronous tasks orchestration","archived":false,"fork":false,"pushed_at":"2018-03-05T09:34:58.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2024-02-26T02:25:38.199Z","etag":null,"topics":["asynchronous-tasks-orchestration","orchestration","queue","tasks"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/keue","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/jmjuanes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-16T09:11:02.000Z","updated_at":"2018-03-08T09:16:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"ba818b30-dd9c-4bc4-944b-9112e6622a81","html_url":"https://github.com/jmjuanes/keue","commit_stats":{"total_commits":56,"total_committers":2,"mean_commits":28.0,"dds":"0.017857142857142905","last_synced_commit":"a29f39cb9ecbc1640cb8f6e585c1ff7f12b38b66"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjuanes%2Fkeue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjuanes%2Fkeue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjuanes%2Fkeue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjuanes%2Fkeue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmjuanes","download_url":"https://codeload.github.com/jmjuanes/keue/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246458812,"owners_count":20780827,"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-tasks-orchestration","orchestration","queue","tasks"],"created_at":"2024-10-25T12:06:39.348Z","updated_at":"2025-03-31T11:23:10.585Z","avatar_url":"https://github.com/jmjuanes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\t\u003cimg width=\"300\" src=\"https://cdn.rawgit.com/jmjuanes/keue/c7658084cd53c010be2a54b8c8e78a88eb7b330e/media/logo.svg\" alt=\"keue\"\u003e\n\t\u003cbr\u003e\n\u003c/div\u003e\n\n# keue\n\n\u003e Asynchronous tasks orchestration\n\n[![npm](https://img.shields.io/npm/v/keue.svg?style=flat-square)](https://www.npmjs.com/package/keue)\n[![npm](https://img.shields.io/npm/dt/keue.svg?style=flat-square)](https://www.npmjs.com/package/keue)\n[![npm](https://img.shields.io/npm/l/keue.svg?style=flat-square)](https://github.com/jmjuanes/keue)\n\n## Install\n\nYou can install the latest version of the package using **npm**:\n\n```\n$ npm install --save keue\n```\n\n## Usage\n\n```javascript\n//Import package\nvar keue = require(\"keue\");\n\n//Generate a new instance\nvar tasks = new keue();\n\n//Register a new sync task \ntasks.addTask(\"task1\", function (done) {\n    //Do some stuff\n    //...\n    \n    //Call the done method when the task is completed\n    return done();\n});\n\n//Register a new async task\ntasks.addTask(\"task2\", function (done) {\n    //Call an asynchronous function\n    return myAsyncFunction(function (error) {\n        if (error) {\n            //If something went wrong, you can stop the tasks execution\n            //calling done method with an error object\n            return done(error);\n        }\n        \n        //Do some stuff\n        //...\n        \n        //Task completed\n        return done();\n    });\n});\n\n//Finish listener\nk.on(\"finish\", function () {\n  //Tasks finished successfully\n  //...\n});\n\n//Task error listener \nk.on(\"error\", function (error) {\n    //Error running a task\n});\n\n//Run the tasks \ntasks.run(\"task1\", \"task2\");\n```\n\n## API\n\n### var tasks = new keue();\n\nInitialize tasks manager.\n\n```javascript\nvar tasks = new keue();\n```\n\n### tasks.addTask(name\\[, dependencies\\], handler);\n\nRegister a new task called `name`. You can optionally provide list of `dependencies` tasks to be executed and completed before this task is executed.\n\nThe last argument should be a function that will be called with the following arguments:\n\n- `done`: a function that should be called when the task is completed. If you call this function with an `Error` object, the tasks queue will be finished and the `error` event will be triggered.\n\n````javascript\n//Add a new task to the queue\ntasks.addTask(\"task1\", function(done) {\n    //If something went wrong running the queue, you can abort it \n    //by calling the next function with an error object \n    if(/* something went wrong */) {\n        //Abort the task \n        return done(new Error(\"Something went wrong\"));\n    } else {\n        //Task completed without error\n        return done();\n    }\n});\n\n//Add a new task with dependencies \ntasks.addTask(\"task2\", [\"task1\"], function(done) {\n    //task1 will be completed before this task is executed\n    //Do your magic\n    //...\n});\n````\n\n### tasks.removeTask(name)\n\nRemoves the task called `name` from the tasks list (if exists).\n\n```javascript\ntasks.removeTask(\"task4\");\n```\n\n### tasks.run(tasks...);\n\nStart running the list of provided tasks. This methods accepts a string or an array of strings with the names of the tasks to run. If no arguments ar passed, all tasks will be executed. The tasks will be executed in the order that you provide to the `tasks.run` method. For example, if you have three tasks (`task1`, `task2`, and `task3`) and you want to execute them in descendant order:\n\n```javascript\ntasks.run(\"task3\", \"task2\", \"task1\"); //First will be executed \"task3\", then \"task2\" and last \"task1\".\n```\n\nOr: \n\n```javascript\ntasks.run([\"task3\", \"task2\", \"task1\"]);\n```\n\nThis method will fire the `start` event. \n\n\n### tasks.on(eventName, eventListener)\n\nRegister the `eventListener` function as a listener of the `eventName` event. \n\n#### event start\n\nThe tasks queue started.\n\n```javascript\ntasks.on(\"start\", function () {\n    //The task queue started\n});\n```\n\n#### event finish\n\nThis event will be fired when the tasks queue finished successfully.\n\n```javascript\ntasks.on(\"finish\", function () {\n    //Tasks finished\n});\n```\n\n#### event error\n\nFired when the tasks queue was aborted due to a task error.\n\n```javascript\ntasks.on(\"error\", function (error) {\n    //Tasks aborted\n});\n```\n\n#### event task:start\n\nFired when a task was started.\n\n```javascript\ntasks.on(\"task:start\", function (name) {\n    console.log(\"Task \" + name + \" started\");\n});\n```\n\n#### event task:end \n\nFired when a task was completed without error. \n\n```javascript\ntasks.on(\"task:end\", function (name) {\n    console.log(\"Task \" + name + \" completed!\");\n});\n```\n\n\n## License\n\n[MIT](./LICENSE) \u0026copy; Josemi Juanes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmjuanes%2Fkeue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmjuanes%2Fkeue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmjuanes%2Fkeue/lists"}