Skip to content

Instantly share code, notes, and snippets.

@bananaumai
Created January 15, 2017 07:38
Show Gist options
  • Save bananaumai/41771d154645cd0a96a68380d79c9729 to your computer and use it in GitHub Desktop.
Save bananaumai/41771d154645cd0a96a68380d79c9729 to your computer and use it in GitHub Desktop.
const delayed_yeah = () => {
console.log('delayed_yeah!')
return new Promise((resolve, reject) => {
setTimeout(() => resolve('yeah!'), 2000)
})
}
const delayed_hi = () => {
console.log('delayed_hi!')
return new Promise((resolve, reject) => {
setTimeout(() => resolve('hi!'), 2000)
})
}
const awfn = async () => {
console.log('before delayed yeah')
const yeah = await delayed_yeah()
console.log('before delayed hi')
const hi = await delayed_hi()
console.log(yeah, hi)
}
let counter = 0
const timeout = setInterval(() => {
if (counter === 5) awfn()
console.log(counter)
counter++
}, 1000)
setTimeout(() => clearInterval(timeout), 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment