Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
const ctrl = new AbortController(); const { signal } = ctrl; const timer = setTimeout(() => ctrl.abort(), 5000); // 5s timeout try { const res = await fetch("/api/data", { signal }); clearTimeout(timer); return res.json(); } catch (e) { if (e.name === "AbortError") console.log("Request cancelled"); else throw e; }
Result
Open