tasking
Tiny tasking system
var create add run = // Create a task system:var task = // Add a sync task: // Add an async task: // Run tasks:
Tiny tasking system based on three simple functions: create
, add
, and run
.
Installation
$ npm install --save tasking
Usage
tasking(name)
tasking.create(name)
Create a task system where tasks and other meta info is stored. tasking.create
alias useful when destructuring
name
(String
): Name of the system.
var task = // Or:var task = tasking
Note: It is nice to name it task
when used with add(task, ...)
and run(task, ...)
, but is also referred to as system
tasking.add(system, name, [deps], [fn])
Add task to a system. Each task has a name associated to dependencies and/or a function
system
(Object
): The return system fromtasking.create
name
(String
): Name of the task you are creaingdeps
(Array
): Tasks to run before this one startsfn
(Function
): Function for the task. Sync or async if it hasdone
param
var add = taskingadd
When ran, the dependencies are run first. Dependencies reference names to other tasks on the same system
If the task's function has a done
parameter, it is ran as async, otherwise it is ran as sync
tasking.run(system, name, [done])
Run task in system. Will run specified dependency tasks first, but only once during the whole execution
system
(Object
): The return system fromtasking.create
name
(String
|Array
): Name or array of names of what you are runningdone
(Function
): Callback after task(s) completed. Defaults to throwing error.
It is important to know that async tasks are run in parallel, use add
+ run
to create serially running tasks:
Also see async-series
Structure
The system and tasks follow an easy-to-use structure:
// System properties:systemnamesystemtasks // Get tasks by name:var foo = systemtasksfoo // Task properties:foofnfoodepsfooname
License
MIT © Jamen Marz