Provides a task manager for organizing and scheduling asynchronous operations
Taskman is a node.js library for managing (possibly) asynchronous operations. This library strives to be different from other asynchronous operations managers by focusing on the relationships between tasks. Tasks that have no dependencies are run first, and tasks that do have dependencies are run as soon as their dependencies have completed.
To use a task manager, you must first instantiate an instance.
var Task = require"node-taskman"task = ;
Then you add your tasks in the form of functions. The task function should call either the finish or cancel method passed in to it once the task has completed/errored. This will trigger any dependents this task has.
var task1 = taskaddconsole.log"I am a task";setTimeoutfinish;1000;;
Next, specify the relationships between the different tasks.
taskcreateDependencytask3 task1 task2;
Finally, run and enjoy!
You can instantiate as many taskmans as you want, and can even nest taskmans inside of each other. See
examples/ for other interesting ways of using taskman.
npm install taskman
Adds a task to the manager.
taskmanaddtaskID dependencies task
- taskID optional The identifier of the task. If ommitted, a task is generated automatically with the form "@###".
- dependencies <String | Array> optional The task ID(s) of the task's dependencies. This is the same as calling taskman.createDependency(task, dependencies).
- task <function(finish, cancel)> The task to add.
- Task ID is already taken.
- Task is not a function.
The task ID of the newly created task.
Cancels the run in progress and calls the cancel callback supplied to Taskman#run, if available.
- customData optional Data to be passed to the cancel callback.
Clears all of the dependencies for the supplied targets
- targets <String | Array> optional The task ID's of the targets to clear the dependencies for. If no targets are specified, all dependencies are cleared.
Creates a dependency between two or more tasks
- targets <String | Array> The task ID(s) target or targets to create dependencies for. If more than one target is supplied, every dependency specified is set as a dependency of each target.
- dependencies <String | Array> The task ID(s) of the dependency or dependencies of the targets.
- Unsupported targets type. The targets parameter is not a string or an array.
- Unsupported dependencies type. The dependencies parameter is not a string or an array.
Resets the task so that it can be used again. All registered tasks and dependencies are discarded.
Runs the scheduled tasks. Any changes to the dependencies after this method is called are ignored.
taskmanrunserializeTasksFlag completion cancel
- serializeTasksFlag Convienience flag that calls Taskman@serializeTasks under the hood
- completion <function()> The function to call once all tasks have completed successfully
- cancel <function(customData)> The function to call if one of the tasks calls Taskman#cancel or its cancel function. The data passed in to Taskman#cancel is supplied as the argument to this function.
Automatically creates a dependency between every task such that the next task does not run until the task before it has completed. Any tasks added after this method is called are not serialized.
Copyright 2012-2013 Bryan Hughes firstname.lastname@example.org
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.