Skip to content

Instantly share code, notes, and snippets.

@a-type
Created July 1, 2021 21:43
Show Gist options
  • Save a-type/faead638a35fe08f56eff2336b65502a to your computer and use it in GitHub Desktop.
Save a-type/faead638a35fe08f56eff2336b65502a to your computer and use it in GitHub Desktop.
Abort controller synchronous call test
var controller = new AbortController();
fetch('/', { signal: controller.signal })
.then(res => res.text())
.then(text => console.log(text));
// busywait for a while, should keep the thread busy until the request
// completes.
let i = 0; while (i < 100000) {
i++;
console.log(i);
}
controller.abort();
... numbers ...
9994
9995
9996
9997
9998
9999
10000
undefined
index:1 Uncaught (in promise) DOMException: The user aborted a request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment