Photo by Artem Maltsev / Unsplash

Async Await Timeout

Today I Learned Jul 21, 2023

sometimes you want to pause for a few seconds in a async
for loop to avoid hitting a rate limit. To do this easily we can create a async version of setTimeout to help us.

const wait = time =>
  new Promise(resolve =>
    setTimeout(() => {
      return resolve(true)
    }, time),
  )

// Use the wait in a async loop etc
await wait(1000)

Tags

Frank Schmidt

Software Dev @ REDspace