diff options
author | Official Noob <[email protected]> | 2019-08-20 17:46:05 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-08-20 17:46:05 +0100 |
commit | a6c77185de21d9398d59c4aa67a08b50ba6d09bf (patch) | |
tree | d0a674f636d39cd6022e8c4d794a786b0382fccb /utils.js | |
parent | adb60c6357ae689e679be5fd55d2719c6796eeb9 (diff) | |
download | SponsorBlock-a6c77185de21d9398d59c4aa67a08b50ba6d09bf.tar.gz SponsorBlock-a6c77185de21d9398d59c4aa67a08b50ba6d09bf.zip |
Added wait function
Diffstat (limited to 'utils.js')
-rw-r--r-- | utils.js | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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; |