|
|
|
|
class Schedule {
|
|
|
|
constructor(msDelay) {
|
|
if(!msDelay){
|
|
msDelay = 100
|
|
}
|
|
this.msDelay = msDelay
|
|
this._once = false
|
|
this.timeOutCount = 0;
|
|
this.timeOut = null
|
|
this.interval = null
|
|
}
|
|
cancelRepeat() {
|
|
clearInterval(this.interval)
|
|
this.interval = null
|
|
}
|
|
cancelDelay() {
|
|
clearTimeout(this.interval)
|
|
this.interval = null
|
|
}
|
|
repeat(func){
|
|
if(this.interval){
|
|
return false
|
|
}
|
|
this.interval = setInterval(()=>{
|
|
func()
|
|
}, this.msDelay)
|
|
}
|
|
delay(func) {
|
|
this.timeOutCount++
|
|
if(this.timeOut){
|
|
this.cancelDelay()
|
|
}
|
|
const me = this
|
|
this.timeOut = setTimeout(()=>{
|
|
clearTimeout(me.timeOut)
|
|
me.timeOut = null
|
|
func(me.timeOutCount)
|
|
me.cancelDelay()
|
|
me.timeOutCount = 0
|
|
}, this.msDelay)
|
|
}
|
|
|
|
} |