Skip to content

Instantly share code, notes, and snippets.

@bellbind
Created June 4, 2020 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bellbind/8dafa0c24228ac7034c566a2c02eb682 to your computer and use it in GitHub Desktop.
Save bellbind/8dafa0c24228ac7034c566a2c02eb682 to your computer and use it in GitHub Desktop.
[DOM][browser] simple AbortController example
<!doctype html>
<html>
<head>
<script type="module">
// https://dom.spec.whatwg.org/#interface-AbortController
const ac = new AbortController();
document.querySelector("#aborted").textContent = ac.signal.aborted;
ac.signal.addEventListener("abort", ev => {
console.log("aborted"); // onabort spawned only once
document.querySelector("#aborted").textContent = ac.signal.aborted;
});
document.querySelector("#abort").addEventListener("click", ev => {
ac.abort();
});
</script>
</head>
<body>
<h1>DOM AbortController Example</h1>
<button id="abort">abort</button>
<label>aborted: <span id="aborted"></span></label>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment