Example 1 — fetch options shape
What you pass to fetch.
JavaScript
const c = new AbortController();
const init = { signal: c.signal };
console.log(!!init.signal);How It Works
- Same object goes to fetch(url, init).
Pass { signal: controller.signal } to fetch. Calling abort() rejects the fetch promise with an AbortError.
const c = new AbortController();
const { signal } = c;
signal.addEventListener("abort", () => console.log("aborted"));
c.abort("user cancel");What you pass to fetch.
const c = new AbortController();
const init = { signal: c.signal };
console.log(!!init.signal);CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful