* Tries to schedule a new pass optionally with specified delay. If the new * requested pass is requested before the pending pass, the pending pass is * canceled. If the new pass is requested after the pending pass, the newly * requested pass is ignored. * * Returns true if the
(opt_delay)
| 62 | * @return {boolean} |
| 63 | */ |
| 64 | schedule(opt_delay) { |
| 65 | let delay = opt_delay || this.defaultDelay_; |
| 66 | if (this.running_ && delay < 10) { |
| 67 | // If we get called recursively, wait at least 10ms for the next |
| 68 | // execution. |
| 69 | delay = 10; |
| 70 | } |
| 71 | |
| 72 | const nextTime = Date.now() + delay; |
| 73 | // Schedule anew if nothing is scheduled currently or if the new time is |
| 74 | // sooner then previously requested. |
| 75 | if (!this.isPending() || nextTime - this.nextTime_ < -10) { |
| 76 | this.cancel(); |
| 77 | this.nextTime_ = nextTime; |
| 78 | this.scheduled_ = this.timer_.delay(this.boundPass_, delay); |
| 79 | |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * |
no test coverage detected