import { default } from "https://deno.land/x/timers@v0.2.0/src/pTimeout.ts";
Timeout a promise after a specified amount of time.
Examples
Example 1
Example 1
import pTimeout from 'https://deno.land/x/timers@v0.2.0/mod.ts'
const delayedPromise = new Promise(resolve => setTimeout(resolve, 500))
await pTimeout({
promise: delayedPromise,
milliseconds: 50
})
//=> [TimeoutError: Promise timed out after 50 milliseconds]
Parameters
promise: Promise<T> | ((signal: AbortSignal) => Promise<T>)
- Promise to decorate.
optional
options: PTimeoutOptions<T> = [UNSUPPORTED]- Do something other than rejecting with an error on timeout. You could for example retry.