Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/delayed/src/timeout.ts>timeout

A simple module that provide an asynchronous approach to interval, delay and timeout
Go to Latest
function timeout
import { timeout } from "https://deno.land/x/delayed@2.0.2/src/timeout.ts";

Execute the callback at least after the specified delay

Examples

const { status } = await timeout(() => fetch('https://deno.land'), 500)
//wait 500ms and then status === 200
timeout(console.log, 1000, {}, 'delayed', 1000, 's')
//print the message "delayed 1000 s" after 1s
const ac = new AbortController()
timeout(exit, 1000, ac, 1)
ac.abort()
//abort timeout before executing "exit" with arg "1"

Type Parameters

TArgs extends unknown[]
optional
TReturn = unknown

Parameters

callback: Callback<TArgs, TReturn>
  • The function to be called after the delay.
delay: ms
  • The amount of time in milliseconds to wait before calling the callback.
optional
unnamed 2: { signal?: AbortSignal; } = [UNSUPPORTED]
  • The arguments of the callback
...args: TArgs

Returns

Promise<TReturn>

A promise that resolves to the value returned by the callback.