🎮 The main controller object that lets you abort operations on demand. Think of it as a remote control for your async operations!

// Example: Implementing a timeout for a network request
async function fetchWithTimeout(url: string, timeout: number) {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeout);

try {
const response = await fetch(url, { signal: controller.signal });
clearTimeout(timeoutId);
return response;
} catch (e) {
if (controller.signal.aborted) {
throw new Error("Request timed out!");
}
throw e;
}
}

Constructors

Accessors

Methods

Constructors

Accessors

Methods

  • Parameters

    • Optionalreason: any

    Returns void