getTimeoutSignal
getTimeoutSignal
is a function that returns an AbortSignal
object that times out after the specified number of milliseconds. It is provided for environments that do not implement AbortSignal.timeout()
.
Import
import { getTimeoutSignal } from "@tai-kun/surrealdb/utils";
Usage
function getTimeoutSignal(milliseconds: number): AbortSignal;
Arguments
milliseconds
Sets the timeout duration in milliseconds.
Return Value
Returns a new AbortSignal
object.
Exceptions
Throws an error in server-side runtimes that lack the AbortSignal.timeout
function. This is due to the high implementation cost of a polyfill. A somewhat forceful implementation is used in browsers.
Example
The following example shows how to set a 5-second timeout for fetch
:
import { getTimeoutSignal } from "@tai-kun/surrealdb/utils";
const resp = await fetch("https://example.com/", { signal: getTimeoutSignal(5000),});