timeout.ts
export function timeout(delay: number) {
return new Promise( res => setTimeout(res, delay) );
}
Context
Sometimes when you are building something you want to see how it works with a little delay. I use this for playing with, or testing, React suspense.
Usage
waitExample.ts
import { timeout } from '../lib/timeout'
await timeout(1000) //for 1 sec delay