task-list
Simple utility library for managing a list of tasks and their lifecycle with support for promises and Node.js-style callbacks.
Installation
npm install task-list --save
Overview
The task-list
module is used to orchestrate starting and
stopping tasks in sequential order.
Each task is provided as an object that provides
a start
function and an optional stop
function.
If your task is asynchronous then your start
/stop
function can either
invoke a callback or return a promise. If returning a promise, then
your start
/stop
function should have no arguments. If not using
promises for your asynchronous operation, then your function should
declare a single callback
argument which will be a Node.js-style
callback that you can invoke to indicate success or failure.
If your task is synchronous then make sure your start
/stop
function
does not declare any arguments. As long as the function doesn't return
something that looks like a Promise
then it will be assumed that
your task completed synchronously.
Usage
Simple example with minimal configuration:
var tasks = ; // Using callback-style to start/stop all taskstasks; // startAll and stopAll can also be invoked with no argument if you// would rather use promises.tasks
An example that provides a logger
:
var options = logger: { console; } { console; } { console; } ; var services = ;
API
create(tasks, options)
Method: Returns a TaskList
which has operations for controlling the lifecycle
of the tasks
options
logger
: An object that hasinfo
,success
, orerror
properties which should be functions that expect a single message argument. Theinfo
,success
, anderror
properties are optional and if not provided then the corresponding log level will not produce any output.
Example:
var tasks =
Class: TaskList
A TaskList
is returned by call to require('task-list').create(...)
.
NOTE: If you call startAll
or stopAll
without a callback argument
then a Promise
will be returned. The Promise
implementation will
be the native Promise
provided by the JavaScript runtime environment
or the Promise
implementation that your application exposed as a
global. If there is no global Promise
implementation found, then
you will encounter exceptions.
startAll([callback])
Method: This method is used to start all of the tasks that belong to this TaskList
.
If a callback is provided then it is expected to be a Node.js-style callback
that will be invoked when all tasks have been started or error occurred.
If a callback is not provided then a Promise
will be returned.
stopAll([callback])
Method: This method is used to stop all of the tasks that belong to this TaskList
.
If a callback is provided then it is expected to be a Node.js-style callback
that will be invoked when all tasks have been stopped or error occurred.
If a callback is not provided then a Promise
will be returned.