wait

go previous

A collection of wait functions for simulating a delay.

import { isDev } from "@/registry/utils/checks/checks";

export async function asyncWait(ms: number) {
  // safe guard so it only runs in dev mode
  if (!isDev()) return;

  await new Promise((resolve) => setTimeout(resolve, ms));
}

export function syncWait(ms: number) {
  // safe guard so it only runs in dev mode
  if (!isDev()) return;

  const start = Date.now();
  let now = start;
  while (now - start < ms) now = Date.now();
}

Installation

pnpm dlx shadcn@latest add https://mhl5.vercel.app/r/wait.json