Added wait function

This commit is contained in:
Official Noob 2019-08-20 17:46:05 +01:00 committed by GitHub
parent adb60c6357
commit a6c77185de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;