mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-08-02 03:26:24 -04:00
test havenod 1.0.2, update dist
This commit is contained in:
parent
d0da85167a
commit
0d51340033
7 changed files with 17 additions and 68 deletions
12
dist/utils/TaskLooper.js
vendored
12
dist/utils/TaskLooper.js
vendored
|
@ -32,15 +32,17 @@ class TaskLooper {
|
|||
/**
|
||||
* Start the task loop.
|
||||
*
|
||||
* @param {int} periodInMs the loop period in milliseconds
|
||||
* @param {number} periodInMs the loop period in milliseconds
|
||||
* @param {boolean} targetFixedPeriod specifies if the task should target a fixed period by accounting for run time (default false)
|
||||
* @return {TaskLooper} this instance for chaining
|
||||
*/
|
||||
start(periodInMs) {
|
||||
start(periodInMs, targetFixedPeriod) {
|
||||
if (periodInMs <= 0)
|
||||
throw new Error("Looper period must be greater than 0 ms");
|
||||
if (this._isStarted)
|
||||
return;
|
||||
this._isStarted = true;
|
||||
this._runLoop(periodInMs);
|
||||
this._runLoop(periodInMs, targetFixedPeriod);
|
||||
}
|
||||
/**
|
||||
* Stop the task loop.
|
||||
|
@ -52,13 +54,13 @@ class TaskLooper {
|
|||
clearTimeout(this._timeout);
|
||||
this._timeout = undefined;
|
||||
}
|
||||
async _runLoop(periodInMs) {
|
||||
async _runLoop(periodInMs, targetFixedPeriod) {
|
||||
this._isLooping = true;
|
||||
while (this._isStarted) {
|
||||
const startTime = Date.now();
|
||||
await this._fn();
|
||||
if (this._isStarted)
|
||||
await new Promise((resolve) => { this._timeout = setTimeout(resolve, periodInMs - (Date.now() - startTime)); });
|
||||
await new Promise((resolve) => { this._timeout = setTimeout(resolve, periodInMs - (targetFixedPeriod ? (Date.now() - startTime) : 0)); });
|
||||
}
|
||||
this._isLooping = false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue