Dan Stroot

Wait

Sometimes when you are testing, or playing around, you just want to simulate some delay. Here's a simple way to do just that.

Date:


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

Sharing is Caring

Edit this page