aboutsummaryrefslogtreecommitdiffhomepage
path: root/utils.js
diff options
context:
space:
mode:
authorOfficial Noob <[email protected]>2019-08-20 17:46:05 +0100
committerGitHub <[email protected]>2019-08-20 17:46:05 +0100
commita6c77185de21d9398d59c4aa67a08b50ba6d09bf (patch)
treed0a674f636d39cd6022e8c4d794a786b0382fccb /utils.js
parentadb60c6357ae689e679be5fd55d2719c6796eeb9 (diff)
downloadSponsorBlock-a6c77185de21d9398d59c4aa67a08b50ba6d09bf.tar.gz
SponsorBlock-a6c77185de21d9398d59c4aa67a08b50ba6d09bf.zip
Added wait function
Diffstat (limited to 'utils.js')
-rw-r--r--utils.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/utils.js b/utils.js
index 178d4e81..e0681d52 100644
--- a/utils.js
+++ b/utils.js
@@ -1,3 +1,17 @@
+// Function that can be used to wait for a condition before returning
+async function wait(condition, timeout = 5000, check = 100) {
+ return await new Promise((resolve, reject) => {
+ setTimeout(() => {reject("TIMEOUT")}, timeout);
+ const interval = setInterval(() => {
+ let result = condition();
+ if (result !== false) {
+ resolve(result);
+ clearInterval(interval);
+ };
+ }, check);
+ });
+}
+
function getYouTubeVideoID(url) {
//Attempt to parse url
let urlObject = null;