Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
Linter auto-fix main, safeInterval, safeScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
joelchoo committed Nov 24, 2017
1 parent bae5c33 commit b46a269
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 182 deletions.
86 changes: 43 additions & 43 deletions beeline/SafeInterval.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import assert from 'assert';

export class SafeInterval {
constructor(fn, interval, retryTimeout) {
this.isRunning = false;
this.timeout = null;

retryTimeout = retryTimeout || interval;

//fn returns a Promise
this.loop = function() {
this.timeout = null;

var promise = this.currentPromise = fn();

this.currentPromise
.then(()=>{
if (promise == this.currentPromise && this.isRunning) {
this.timeout = setTimeout(this.loop, interval);
}
})
.catch((err) => {
console.log(err)
if (promise == this.currentPromise && this.isRunning) {
this.timeout = setTimeout(this.loop, retryTimeout);
}
})
}.bind(this);
}

stop() {
this.isRunning = false;
if (this.timeout !== null) {
clearTimeout(this.timeout);
}
}

start() {
if (this.isRunning) return;
this.isRunning = true;
this.loop();
}
}
import assert from 'assert'

export class SafeInterval {
constructor (fn, interval, retryTimeout) {
this.isRunning = false
this.timeout = null

retryTimeout = retryTimeout || interval

// fn returns a Promise
this.loop = function () {
this.timeout = null

let promise = this.currentPromise = fn()

this.currentPromise
.then(()=>{
if (promise == this.currentPromise && this.isRunning) {
this.timeout = setTimeout(this.loop, interval)
}
})
.catch((err) => {
console.log(err)
if (promise == this.currentPromise && this.isRunning) {
this.timeout = setTimeout(this.loop, retryTimeout)
}
})
}.bind(this)
}

stop () {
this.isRunning = false
if (this.timeout !== null) {
clearTimeout(this.timeout)
}
}

start () {
if (this.isRunning) return
this.isRunning = true
this.loop()
}
}
80 changes: 40 additions & 40 deletions beeline/SafeScheduler.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import assert from 'assert';

export class SafeScheduler {
constructor(fn, hours, minutes = 0, seconds = 0) {
this.isRunning = false;
this.timeout = null;

//fn returns a Promise
this.loop = function() {
this.timeout = null;

fn()
.then(()=>{
if (this.isRunning) {
this.timeout = setTimeout(this.loop,
new Date().setHours(hours, minutes, seconds) - Date.now()
);
}
})
.catch(() => {
if (this.isRunning) {
this.timeout = setTimeout(this.loop, 60000 /* retryTimeout */);
}
})
}.bind(this);
}

stop() {
this.isRunning = false;
if (this.timeout !== null) {
clearTimeout(this.timeout);
}
}

start() {
assert (!this.isRunning);
this.isRunning = true;
this.loop();
}
}
import assert from 'assert'

export class SafeScheduler {
constructor (fn, hours, minutes = 0, seconds = 0) {
this.isRunning = false
this.timeout = null

// fn returns a Promise
this.loop = function () {
this.timeout = null

fn()
.then(()=>{
if (this.isRunning) {
this.timeout = setTimeout(this.loop,
new Date().setHours(hours, minutes, seconds) - Date.now()
)
}
})
.catch(() => {
if (this.isRunning) {
this.timeout = setTimeout(this.loop, 60000 /* retryTimeout */)
}
})
}.bind(this)
}

stop () {
this.isRunning = false
if (this.timeout !== null) {
clearTimeout(this.timeout)
}
}

start () {
assert(!this.isRunning)
this.isRunning = true
this.loop()
}
}
Loading

0 comments on commit b46a269

Please sign in to comment.