Skip to main content

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

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

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 Score
100%
Published
2 weeks ago (1.0.11)
function deadline
deadline<T>(
p: Promise<T>,
ms: number,
options?: DeadlineOptions,
): Promise<T>

Create a promise which will be rejected with DOMException when a given delay is exceeded.

Note: Prefer to use AbortSignal.timeout instead for the APIs that accept AbortSignal.

Examples

Usage

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

const delayedPromise = delay(1_000);
// Below throws `DOMException` after 10 ms
const result = await deadline(delayedPromise, 10);

Type Parameters

The type of the provided and returned promise.

Parameters

The promise to make rejectable.

Duration in milliseconds for when the promise should time out.

optional
options: DeadlineOptions

Additional options.

Return Type

A promise that will reject if the provided duration runs out before resolving.

Throws

DOMException & { name: "TimeoutError"
DOMException & { name: "AbortError"
AbortSignal["reason"]

If the optional signal is aborted with a custom reason before resolving or timing out.

Add Package

deno add jsr:@std/async

Import symbol

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

---- OR ----

Import directly with a jsr specifier

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

Add Package

npx jsr add @std/async

Import symbol

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

Add Package

yarn dlx jsr add @std/async

Import symbol

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

Add Package

pnpm dlx jsr add @std/async

Import symbol

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

Add Package

bunx jsr add @std/async

Import symbol

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