Guest User

Untitled

a guest
May 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
  2. const asyncForEach = async (array, callback) => {
  3. for (let index = 0; index < array.length; index++) {
  4. await callback(array[index], index, array)
  5. }
  6. }
  7.  
  8. const start = async () => {
  9. await asyncForEach([1, 2, 3], async (num) => {
  10. await waitFor(50)
  11. console.log(num)
  12. })
  13. console.log('Done')
  14. }
  15.  
  16. start()
Add Comment
Please, Sign In to add comment