Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brettlangdon/continuous
Event based interface to setTimeout and setInterval.
https://github.com/brettlangdon/continuous
Last synced: about 1 month ago
JSON representation
Event based interface to setTimeout and setInterval.
- Host: GitHub
- URL: https://github.com/brettlangdon/continuous
- Owner: brettlangdon
- License: mit
- Created: 2012-07-11T12:18:23.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-08-23T13:00:08.000Z (over 12 years ago)
- Last Synced: 2024-10-12T22:44:43.995Z (3 months ago)
- Language: JavaScript
- Size: 105 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![build status](https://secure.travis-ci.org/brettlangdon/Continuous.png)](http://travis-ci.org/brettlangdon/Continuous)
#Continuous##About
Continuous is an event based utility used for setTimeout and setInterval.
It is useful when trying to have code that runs at random or continuous intervals.##How to Install:
```
npm install continuous
```##How to Use:
```
var continuous = require('continuous');
//tell it to run 5 times
//every 1 to 3 seconds
var options = {
limit: 5,
minTime: 1000,
maxTime: 3000,
callback: function(){
console.log('I have run');
return Math.round(new Date().getTime()/1000.0);
},
random: true
};
var run = new continuous( options );run.on('started', function(){
console.log('It has begun to run');
});
run.on('stopped', function(){
console.log('All Done');
});
run.on('complete', function(count, result){
console.log('I have run ' + count + ' times');
console.log('The return of callback is:');
console.dir(result);
});
//start it
run.start();
//force it to stop after 5 seconds
setTimeout( function(){
run.stop();
}, 5000 );
```##Options:
* `limit`: Number - optional, default: -1(forever)
* `time`: Number - milliseconds between runs (non-random only), default: 1000
* `minTime`: Number - min allowed milliseconds between runs (random only), default: 0
* `maxTime`: Number - max allowed milliseconds between runs (random only), default: 1000
* `random`: Boolean - whether or not it should run randomly between minTime and maxTime, default: false
* `callback`: Function - function to run continuously
##Methods:* `start()` - start running
* `stop()` - stop running