Created
October 30, 2018 21:33
-
-
Save davidchc/1a9e167100ac022ca8fea4251c849998 to your computer and use it in GitHub Desktop.
Exemplo de Sleep com JavaScript
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
let data = [1,2,3,4,5,6,7,8,9,10]; | |
let factor = 2; | |
const sleep = async (ms) => { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
}; | |
const start = async (data) => { | |
let total = data.length; | |
for(let i = 0; i < total; i++) { | |
if(i % factor == 0) { | |
console.log(data[i]); | |
await sleep(2000); | |
} | |
} | |
} | |
start(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment