close
Skip to main content
This release is versions behind 1.4.0 — the latest version of @std/async.

@std/async@1.3.0
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
License
MIT
Downloads27,157/wk
Publisheda month ago (1.3.0)

Utilities for asynchronous operations, like delays, debouncing, or pooling

function delay
delay(
ms: number,
options?: DelayOptions
): Promise<void>

Resolve a Promise after a given amount of milliseconds.

If the optional signal is aborted before the delay duration, the returned promise rejects with the signal's reason. If no reason is provided to abort(), the browser's default DOMException with name "AbortError" is used.

Examples

Basic usage

import { delay } from "@std/async/delay";

// ...
const delayedPromise = delay(100);
const result = await delayedPromise;
// ...

Disable persistence

Setting persistent to false will allow the process to continue to run as long as the timer exists.

import { delay } from "@std/async/delay";

// ...
await delay(100, { persistent: false });
// ...

Parameters

Duration in milliseconds for how long the delay should last.

optional
options: DelayOptions

Additional options.

Return Type

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/async

Import symbol

import { delay } from "@std/async";
or

Import directly with a jsr specifier

import { delay } from "jsr:@std/async";