deno.land / std@0.166.0 / async / deadline.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
import { deferred } from "./deferred.ts";
export class DeadlineError extends Error { constructor() { super("Deadline"); this.name = "DeadlineError"; }}
/** * Create a promise which will be rejected with DeadlineError when a given delay is exceeded. */export function deadline<T>(p: Promise<T>, delay: number): Promise<T> { const d = deferred<never>(); const t = setTimeout(() => d.reject(new DeadlineError()), delay); return Promise.race([p, d]).finally(() => clearTimeout(t));}
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago