keue
Asynchronous tasks orchestration
Install
You can install the latest version of the package using npm:
$ npm install --save keue
Usage
//Import packagevar keue = ; //Generate a new instancevar tasks = ; //Register a new sync task tasks; //Register a new async tasktasks; //Finish listenerk; //Task error listener k; //Run the tasks tasks;
API
var tasks = new keue();
Initialize tasks manager.
var tasks = ;
tasks.addTask(name[, dependencies], handler);
Register a new task called name
. You can optionally provide list of dependencies
tasks to be executed and completed before this task is executed.
The last argument should be a function that will be called with the following arguments:
done
: a function that should be called when the task is completed. If you call this function with anError
object, the tasks queue will be finished and theerror
event will be triggered.
//Add a new task to the queuetasks; //Add a new task with dependencies tasks;
tasks.removeTask(name)
Removes the task called name
from the tasks list (if exists).
tasks;
tasks.run(tasks...);
Start 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:
tasks; //First will be executed "task3", then "task2" and last "task1".
Or:
tasks;
This method will fire the start
event.
tasks.on(eventName, eventListener)
Register the eventListener
function as a listener of the eventName
event.
event start
The tasks queue started.
tasks;
event finish
This event will be fired when the tasks queue finished successfully.
tasks;
event error
Fired when the tasks queue was aborted due to a task error.
tasks;
event task:start
Fired when a task was started.
tasks;
event task:end
Fired when a task was completed without error.
tasks;
License
MIT © Josemi Juanes.