(time)
| 23 | } |
| 24 | |
| 25 | schedule(time) { |
| 26 | if (this._stopped) return; |
| 27 | |
| 28 | const now = Date.now(); |
| 29 | |
| 30 | if (time < 0 || time == null || isNaN(time)) { |
| 31 | // Times earlier than 0 signify maximum delay. |
| 32 | time = now + this._maxDelay; |
| 33 | } else if (time <= now) { |
| 34 | // If it's in the past, trigger immediately, and reschedule to max delay. |
| 35 | this._schedule(now + this._maxDelay); |
| 36 | return this.emit('trigger'); |
| 37 | } else { |
| 38 | // Don't try to schedule past the maximum delay. |
| 39 | time = Math.min(time, now + this._maxDelay); |
| 40 | } |
| 41 | |
| 42 | // Only overwrite the existing timer if later than the given time. |
| 43 | if (!this._timer || time < this._nextTime) { |
| 44 | this._schedule(time); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | stop() { |
| 49 | this._stop(); |
no test coverage detected