Created
May 28, 2021 09:11
-
-
Save guaiamum/e38bf4ce9602f68c1040252a1bd00097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import Queue from 'queue-promise' | |
const newPage = () => { console.log('newPage called'); } | |
const window = { lpTag: {} } | |
// script loading | |
setTimeout(() => { window.lpTag.newPage = newPage; console.log('script arrived'); }, 1500) | |
// ************ QUEUE | |
// const queue = new Queue({ | |
// interval: 1000, | |
// start: false | |
// }); | |
// // log on start | |
// queue.on("start", () => { console.log('/* … */ started it') }); | |
// // calling: window.lpTag.newPage() | |
// queue.add(() => { | |
// window.lpTag.newPage() | |
// }) | |
// // setTimeout(() => { queue.start() }, 2000) | |
// *********** MIMOSA | |
const waitUntil = async (condition) => { | |
return new Promise(resolve => { | |
const interval = setInterval(() => { | |
console.log('checking condition', condition); | |
if (condition()) { | |
console.log('condition passed'); | |
resolve(); | |
clearInterval(interval); | |
} | |
}, 500); | |
}); | |
} | |
waitUntil(() => !!window.lpTag.newPage).then(() => window.lpTag.newPage()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment