Last active
February 2, 2022 16:00
-
-
Save YuriFontella/ec71059462c09cfab4fe79f19adfe49d 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
(async () => { | |
console.time() | |
async function delay(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)) | |
} | |
const time = 2000 | |
const total = 2 | |
const pause = 6000 | |
const array = ['godzilla', 'homer', 'eminem', 'valorant', 'megan fox', 'yuri', 'stalin', 'graphql'] | |
let counter = 0 | |
await Promise.all(array.map(async (x, i) => { | |
if (i > 0) { | |
await delay((i + 1) * time) | |
} | |
console.log(x) | |
counter = counter + 1 | |
if (counter === total) { | |
console.log('\npause\n') | |
counter = 0 | |
await delay(pause) | |
} | |
})) | |
console.timeEnd() | |
})() |
Author
YuriFontella
commented
Feb 2, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment