Skip to content

Instantly share code, notes, and snippets.

@guaiamum
Created May 28, 2021 09:11
Show Gist options
  • Save guaiamum/e38bf4ce9602f68c1040252a1bd00097 to your computer and use it in GitHub Desktop.
Save guaiamum/e38bf4ce9602f68c1040252a1bd00097 to your computer and use it in GitHub Desktop.
// 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