Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/dtils/deps.ts>asyncUtils.deadline

The best unofficial library of utilities for Deno applications
Go to Latest
function asyncUtils.deadline
import { asyncUtils } from "https://deno.land/x/dtils@2.5.0/deps.ts";
const { deadline } = asyncUtils;

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

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

Examples

Example 1

import { deadline } from "https://deno.land/std@0.224.0/async/deadline.ts";
import { delay } from "https://deno.land/std@0.224.0/async/delay.ts";

const delayedPromise = delay(1000);
// Below throws `DeadlineError` after 10 ms
const result = await deadline(delayedPromise, 10);

Parameters

p: Promise<T>
ms: number
optional
options: DeadlineOptions = [UNSUPPORTED]

Returns

Promise<T>