npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

taskman

v1.0.0

Published

Provides a task manager for organizing and scheduling asynchronous operations

Downloads

12

Readme

Taskman

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 = new 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 = task.add(function(finish, cancel){
	console.log("I am a task");
	setTimeout(function(){
		finish();
	}, 1000);
});

Next, specify the relationships between the different tasks.

task.createDependency(task3, [task1, task2]);

Finally, run and enjoy!

task.run(function(){
	console.log("success!");
})

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.

Install

In node.js and npm:

npm install taskman

Methods

add

Description

Adds a task to the manager.

Signature

taskman.add(taskID, dependencies, task)

Parameters

  • 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.

Throws

  • Task ID is already taken.
  • Task is not a function.

Returns

The task ID of the newly created task.

cancel

Description

Cancels the run in progress and calls the cancel callback supplied to Taskman#run, if available.

Signature

taskman.cancel(customData)

Parameters

  • customData optional Data to be passed to the cancel callback.

clearDependencies

Description

Clears all of the dependencies for the supplied targets

Signature

taskman.clearDependencies(targets)

Parameters

  • 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.

createDependency

Description

Creates a dependency between two or more tasks

Signature

taskman.createDependency(targets, dependencies)

Parameters

  • 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.

Throws

  • 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.

reset

Description

Resets the task so that it can be used again. All registered tasks and dependencies are discarded.

Signature

taskman.reset()

run

Description

Runs the scheduled tasks. Any changes to the dependencies after this method is called are ignored.

Signature

taskman.run(serializeTasksFlag, completion, cancel)

Parameters

  • 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.

serializeTasks

Description

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.

Signature

taskman.serializeTasks()

License

Copyright 2012-2013 Bryan Hughes [email protected]

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

http://www.apache.org/licenses/LICENSE-2.0

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.