1.0.2 • Published 9 years ago

time-manager v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

Time Manager

##Install

npm install time-manager --save

Timer

Timer(interval float, method function)

  • interval : float interval value in seconds
  • method : function function to execute every (interval) seconds

This function return an object instance with the following methods :

  • start() : start the Timer
  • stop() : stop the Timer
  • index() : get the current index
  • index(value int) : set the current index

Example

var Timer       = require('time-manager').Timer;
var FirstLoop   = Timer(interval, FirstProcessing);
var SecondLoop  = Timer(interval, SecondProcessing);

function FirstProcessing(index){
    console.log('['+ index +']', 'First processing ...', );

    if(FirstLoop.index() == 3){
        FirstLoop.index(0);
    }
}

FirstLoop.start();



function SecondProcessing(index){
    console.log('['+ index +']', 'Second processing ... ');
    if(SecondLoop.index() == 6){
        console.log('Stop loop.');
        SecondLoop.stop();
    }
}

SecondLoop.start();

CronTab

var CronTab = require('time-manager').CronTab;
var Cron    = new CronTab();

Cron
  .on('error-log', function(log){
    console.log('new error log: ', log);
  })
  .subscribe(['19', '*', '*/5'], function(){
    console.log('Go ! ');
  })
  .subscribe(['10,12,14,16,18', '*', '*/5'], function(){
    console.log('Go ! ');
  });