2.0.1 • Published 10 years ago
tasks-subscribe v2.0.1
Tasks Subscribe
Task Manager with Subscribers for node.
Installation
$ npm install tasks-subscribe
Example
var TaskManager = require('tasks-subscribe');
var userId = 1; // user id, will be subscribed at the start
var output = [];
// Get TaskManager Environment By UserID
// And create task with some calculations
var task = TaskManager(userId).addTask(function(){
this.trigger('test', {hello: 'hello world!'}); // trigger test event
this.done();
}).settings({
some: 'task',
name: 'Task Example'
}).on('done', function(){
output.push(['completed', this.get('some')]); // completed task
output.push(['users subscribed on done', this.getSubscribers()]); // get subscribers at end
}).on('test',function(context){
output.push([context.hello]); // hello world!
output.push(['users subscribed at test event', this.getSubscribers()]); // get subscribers at any event
});
task.start(); // Run task
TaskManager().on('done', function(){
console.log(output);
});
/*
[ [ 'hello world!' ],
[ 'users subscribed at test event', [ 1, 3 ] ],
[ 'completed', 'task' ],
[ 'users subscribed on done', [ 1, 3 ] ] ]
*/
task.subscribe(3);
- First Local Events
- Second Global Events