Create timeout in an async function

To throttle the execution of our async function we will create a timeout method.

Sometimes you just want to delay the execution in your async functions. This could be useful if you create any recursive or waterfall logic.

To do this just create a timeout function:

timeout(ms) {
  return new Promise((resolve) => window.setTimeout(resolve, ms))

Then use it in your async functions like this:

await this.timeout(2000)