Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

continuous

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

continuous - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

example/interval.js

48

index.js

@@ -5,3 +5,2 @@ var event = require('eventemitter2').EventEmitter2;

var continuous = function( options ){
options = (options)?options:{};

@@ -11,7 +10,12 @@

this.time = (options.time)?parseInt(options.time):1000;
this.minTime = (options.minTime)?parseInt(options.minTime):0;
this.maxTime = (options.maxTime)?parseInt(options.maxTime):1000;
this.random = (options.random)?options.random==true:false;
this.callback = (typeof(options.callback)=='function')?options.callback:function(){};
this.interval = null;
this.timeout = null;
this.random = (options.random)?options.random==true:false;
this.count = 0;
this._interval = null;
this._timeout = null;
this._count = 0;
this._running = false;
};

@@ -21,5 +25,7 @@ util.inherits(continuous, event);

continuous.prototype.stop = function(){
clearInterval(this.interval);
clearTimeout(this.timeout);
this._running = false;
clearInterval(this._interval);
clearTimeout(this._timeout);
this.emit('stopped');

@@ -29,22 +35,26 @@ };

continuous.prototype.start = function(){
this.run();
this._count = 0;
this._running = true;
this._run();
this.emit('started');
};
continuous.prototype.run = function(){
continuous.prototype._run = function(){
if( !this._running ) return;
var self = this;
if( this.random ){
this.timeout = setTimeout( function(){
this._timeout = setTimeout( function(){
var result = self.callback();
++self.count;
self.emit('complete', self.count, result);
if( self.count == self.limit ) self.stop();
self.run();
}, self.randomNumber(0,self.time) );
++self._count;
self.emit('complete', self._count, result);
if( self._count == self.limit ) self.stop();
self._run();
}, self.randomNumber(self.minTime,self.maxTime) );
} else{
this.interval = setInterval( function(){
this._interval = setInterval( function(){
var result = self.callback();
++self.count;
self.emit('complete', self.count, result);
if( self.count == self.limit ) self.stop();
++self._count;
self.emit('complete', self._count, result);
if( self._count == self.limit ) self.stop();
}, self.time );

@@ -51,0 +61,0 @@ }

{
"name": "continuous"
, "version": "0.1.0"
, "version": "0.1.1"
, "description": "Event based utility for setTimeout and setInterval"

@@ -10,2 +10,4 @@ , "homepage": "http://www.blangdon.com/"

, "interval"
, "continuously"
, "event"
]

@@ -16,2 +18,8 @@ , "author": "Brett Langdon <brett@blangdon.com>"

]
, "licenses": [
{
"type": "OSL-3.0"
, "url": "http://www.opensource.org/licenses/OSL-3.0"
}
]
, "repository":{

@@ -18,0 +26,0 @@ "type": "hg"

@@ -18,6 +18,7 @@ #Continuous

//tell it to run 5 times
//every 0 to 3 seconds
//every 1 to 3 seconds
var options = {
limit: 5,
time: 3000,
minTime: 1000,
maxTime: 3000,
callback: function(){

@@ -58,4 +59,6 @@ console.log('I have run');

limit: Number //optional, default: -1(forever)
time: Number //milliseconds between when it is run (max time for random), default: 1000
random: Boolean //whether or not it should run randomly between 0 and time, default: false
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

@@ -62,0 +65,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc