Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Ticker(tickerId, baseDelay=3000, ticksCount=10)
- {
- //let this = {};
- this.tickerId = tickerId;
- this.delay = baseDelay;
- this.ticksCount = ticksCount;
- this.cnt = 0;
- this.id;
- this.arm = function()
- {
- this.cnt = 0;
- this.id = setTimeout(function ticker(){
- console.log(`Ticker #${this.tickerId} ${this.cnt}`);
- (this.cnt++) % 2 ? this.delay *= 2 : this.delay /= 2;
- if (this.cnt == this.ticksCount && this.ticksCount != -1) { clearTimeout(this.id); }
- else { this.id = setTimeout(ticker, this.delay)};
- },this.delay);
- };
- this.disarm = function()
- {
- clearTimeout(this.id);
- };
- this.set = function(baseDelay=3000, ticksCount=10)
- {
- this.delay = baseDelay;
- this.ticksCount = ticksCount;
- };
- this.get = function()
- {
- console.log(`Ticker #${this.tickerId}\nDelay: ${this.delay}\nTicksCount: ${this.ticksCount}`);
- }
- //return this;
- };
Add Comment
Please, Sign In to add comment