From 10f1bae7de7257e18a2c6deb7c8184f9154f199e Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 28 Apr 2020 03:04:15 +0200 Subject: [PATCH] move sleep function to a separate fire --- src/ext/lib/Util.js | 3 +++ src/ext/lib/ar-detect/ArDetector.js | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 src/ext/lib/Util.js diff --git a/src/ext/lib/Util.js b/src/ext/lib/Util.js new file mode 100644 index 0000000..51b48a3 --- /dev/null +++ b/src/ext/lib/Util.js @@ -0,0 +1,3 @@ +export async function sleep(timeout) { + return new Promise( (resolve, reject) => setTimeout(() => resolve(), timeout)); +} diff --git a/src/ext/lib/ar-detect/ArDetector.js b/src/ext/lib/ar-detect/ArDetector.js index 3c05561..4af5875 100644 --- a/src/ext/lib/ar-detect/ArDetector.js +++ b/src/ext/lib/ar-detect/ArDetector.js @@ -8,6 +8,7 @@ import GuardLine from './GuardLine'; // import DebugCanvas from './DebugCanvas'; import VideoAlignment from '../../../common/enums/video-alignment.enum'; import AspectRatio from '../../../common/enums/aspect-ratio.enum'; +import {sleep} from '../../lib/Util'; class ArDetector { @@ -257,7 +258,7 @@ class ArDetector { while (!this._exited && exitedRetries --> 0) { this.logger.log('warn', 'debug', `[ArDetect::main] <@${this.arid}> We are trying to start another instance of autodetection on current video, but the previous instance hasn't exited yet. Waiting for old instance to exit ...`); - await this.sleep(this.settings.active.arDetect.timers.tickrate); + await sleep(this.settings.active.arDetect.timers.tickrate); } if (!this._exited) { this.logger.log('error', 'debug', `[ArDetect::main] <@${this.arid}> Previous instance didn't exit in time. Not starting a new one.`); @@ -302,16 +303,13 @@ class ArDetector { } } - await this.sleep(this.settings.active.arDetect.timers.tickrate); + await sleep(this.settings.active.arDetect.timers.tickrate); } this.logger.log('info', 'debug', `%c[ArDetect::main] <@${this.arid}> Main autodetection loop exited. Halted? ${this._halted}`, _ard_console_stop); this._exited = true; } - async sleep(timeout) { - return new Promise( (resolve, reject) => setTimeout(() => resolve(), timeout)); - } canTriggerFrameCheck(lastFrameCheckStartTime) { if (this._paused) {