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

x/dtils/deps.ts>asyncUtils.abortablePromise

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

Make Promise abortable with the given signal.

Examples

Example 1

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

const request = fetch("https://example.com");

const c = new AbortController();
setTimeout(() => c.abort(), 100);

const p = abortablePromise(request, c.signal);

// The below throws if the request didn't resolve in 100ms
await p;

Parameters

p: Promise<T>
signal: AbortSignal

Returns

Promise<T>