Skip to content

Instantly share code, notes, and snippets.

@itacirgabral
Created May 15, 2020 00:59
Show Gist options
  • Save itacirgabral/6203992d27da37b285cd910cee813bc6 to your computer and use it in GitHub Desktop.
Save itacirgabral/6203992d27da37b285cd910cee813bc6 to your computer and use it in GitHub Desktop.
var arrayzao = [
'a',
'e',
'i',
'o',
'u',
'æ'
]
const delay = x => new Promise(res => {
const delay = (1 + Math.random()) * 300
setTimeout(() => res(x), delay)
})
const gen = function *(arr) {
for (let i=0; i<arr.length; i=i+2) {
yield Promise.all([delay(arr[i]), delay(arr[i + 1])])
}
}
;(async () => {
for await (const [a0, a1] of gen(arrayzao)) {
console.log(`a0=${a0} a1=${a1}`)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment