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;