Skip to main content
Module

x/timers/mod.ts>delay

All timing functions you need - for Deno and the browser
Go to Latest
function delay
import { delay } from "https://deno.land/x/timers@v0.2.0/mod.ts";

Resolves after the given number of milliseconds.

Parameters

delay: number | string

the delay as string containing the time in a human readable format (e.g. "1 day and 3hours") or a number of in milliseconds

const MSG = "Please type your name";
const info = document.querySelector("p.info");
const nameInput = document.querySelector("input.name");
const abort = new AbortController();
const { signal } = abort;

nameInput.addEventListener("input", () => abort.abort(), { once: true });

await delay(2000, {
signal
});

info.textContent = MSG;
optional
options: Omit<TimeoutOptions, "args"> = [UNSUPPORTED]