async-task-mgr
A simple nodeJS module for async task manager. Identical tasks will be executed only once and the result will be saved for further use.
Last updated 12 years ago by ottomao .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install async-task-mgr 
SYNC missed versions from official npm registry.

async-task-mgr

Intro

A simple nodeJS module for async task manager. Identical tasks will be executed only once and the result will be saved for further use.

Features

  • tasks with the same name are identified as the same, and will be executed only once
  • task result will be saved for further use

How to use

npm install async-task-mgr --save

Sample

var asyncTask = require("async-task-mgr");

var asyncTaskInstance = new asyncTask();

function taskAction(callback){
	setTimeout(function(){ //simulate an async task
		var resultA = Math.floor(Math.random()*100),
			resultB = Math.floor(Math.random()*100),
			resultC = Math.floor(Math.random()*100);

		callback(resultA, resultB, resultC);
	},2000); 
}

//add a new task named task_A
//when taskAction is done, its return value will be saved and apply to all the task with the same name
asyncTaskInstance.addTask("task_A",taskAction,function(resultA,resultB,resultC){ 
	console.log("task A_1 result :" + resultA + " " + resultB + " " + resultC); //all result generated by taskAction will be passed here
});


//add a new task named task_A
/*
since a task with the same name has been added, this taskAction will not be executed.
the callback function will be put in a queue and will be called when previous callbacks are done.
*/
asyncTaskInstance.addTask("task_A",taskAction,function(resultA,resultB,resultC){
	console.log("task A_2 result :" + resultA + " " + resultB + " " + resultC);
});


//add a new task named task_X
//a new task, have no relationship to the previous ones
asyncTaskInstance.addTask("task_X",taskAction,function(resultA,resultB,resultC){
	console.log("task X_0 result :" + resultA + " " + resultB + " " + resultC);
});

Author

Otto Mao ottomao@gmail.com

Current Tags

  • 1.1.0                                ...           latest (12 years ago)

4 Versions

  • 1.1.0                                ...           12 years ago
  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 13
Today 0
This Week 0
This Month 8
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE