()
| 607 | } |
| 608 | |
| 609 | wake() { |
| 610 | const currentTime = processTimeMS(); |
| 611 | const timeSinceLastCall = currentTime - this.lastExecutionEnded; |
| 612 | |
| 613 | // TODO(NODE-4674): Add error handling and logging to the monitor |
| 614 | if (timeSinceLastCall < 0) { |
| 615 | return this._executeAndReschedule(); |
| 616 | } |
| 617 | |
| 618 | if (this.isExecutionInProgress) { |
| 619 | return; |
| 620 | } |
| 621 | |
| 622 | // debounce multiple calls to wake within the `minInterval` |
| 623 | if (this.isExpeditedCallToFnScheduled) { |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | // reschedule a call as soon as possible, ensuring the call never happens |
| 628 | // faster than the `minInterval` |
| 629 | if (timeSinceLastCall < this.minHeartbeatFrequencyMS) { |
| 630 | this.isExpeditedCallToFnScheduled = true; |
| 631 | this._reschedule(this.minHeartbeatFrequencyMS - timeSinceLastCall); |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | this._executeAndReschedule(); |
| 636 | } |
| 637 | |
| 638 | stop() { |
| 639 | this.stopped = true; |
no test coverage detected