Merge pull request #121 from OfficialNoob/patch-18

Added wait function
This commit is contained in:
Ajay Ramachandran 2019-08-21 13:47:57 -04:00 committed by GitHub
commit 0bef50e259
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;