justsml / dans-blog

the new danlevy.net
https://danlevy.net
14 stars 4 forks source link

"YMNN Axios" Missing Examples #70

Open justsml opened 4 years ago

justsml commented 4 years ago

TODO

justsml commented 4 years ago

Canceling a Request with AbortController & fetch()

credit

const controller = new AbortController();
const signal = controller.signal;

const timer = setTimeout(() => controller.abort(), 5000);

fetch(url, { signal }).then(response => {
  return response.text();
}).then(text => {
  console.log(text);
  clearTimeout(timer);
});