micro-tasks
v0.0.0
Published
Simple task utility that runs tasks as micro tasks via promises.
Readme
Micro Tasking Library
Simple task utility that runs tasks as micro tasks via promises.
Install
NPM
- Use:
require('micro-tasks') - Install:
npm install --save micro-tasks
Bower
- Use:
require('micro-tasks') - Install:
bower install micro-tasks
Documentation
Usage
####Single micro tasks
// creates a MicroTaskQueue, then passes in some optional data
var data = 0;
queue = new MicroTaskQueue(data);
// the following functions are added in no specific order
// adds a single micro task
queue.addTask(function(data) {
console.log("task " + data);
return data + 1;
})
// optional done handler called when all tasks are complete
.done(function(result) {
if (result instanceof Error)
console.error(result)
else
console.log("complete " + result);
});
queue.run(data);####Multiple micro tasks
// creates a MicroTaskQueue, then passes in some optional data
var data = 1,
queue = new MicroTaskQueue();
// adds a batch of micro tasks
queue.addTasks([
function(data) {
console.log("task " + data);
return data + 1;
},
function(data) {
console.log("task " + data);
return data + 1;
},
function(data) {
console.log("task " + data);
return data + 1;
}
])
// optional done handler called when all tasks are complete
.done(function(result) {
if (result instanceof Error)
console.error(result)
else
console.log("complete " + result);
});
queue.run(data);####Monitoring single tasks
// create a MonitoredTaskQueue, this example passes in some optional data
var data = 0;
var queue = new MonitoredTaskQueue();
// the following functions are added in no specific order
// optional beforeEach task handler
queue.beforeEach(function (data) {
return data + 1;
})
// optional afterEach task handler
.afterEach(function (data) {
return data + 1;
})
// adds a task with a taskDone callback handler
.addTask(function (data) {
return data + 1;
}, function taskDone(data) {
return data + 1;
})
// optional done handler called when all tasks are complete
.done(function (result) {
if (result instanceof Error)
console.error(result)
else
console.log("complete " + result);
});
queue.run(data);####Monitoring task batches
var data = 0;
// create a MonitoredTaskQueue, this example passes in some optional data
var queue = new MonitoredTaskQueue();
// the following functions are added in no specific order
// optional beforeEach task handler
queue.beforeEach(function (data) {
return data + 1;
})
// optional afterEach task handler
.afterEach(function (data) {
return data + 1;
})
// adds a batch of tasks with a taskBatchDone callback handler
// which is called once the batch of tasks are complete
.addTasks([
function (data) {
return data + 1;
},
function (data) {
return data + 1;
},
function (data) {
return data + 1;
}
], function taskBatchDone(data) {
return data + 1;
})
// optional done handler called when all tasks are complete
.done(function (result) {
if (result instanceof Error)
console.error(result)
else
console.log("complete " + result);
});
queue.run(data);Backers
Maintainers
These amazing people are maintaining this project:
- pflannery (https://github.com/pflannery)
Sponsors
No sponsors yet! Will you be the first?
Contributors
These amazing people have contributed code to this project:
License
Licensed under GNU GPL v3
Copyright © 2015+ pflannery (https://github.com/pflannery)
