developit/unfetch

add support for aborting via AbortController

Open

#54 建立於 2017年9月29日

在 GitHub 查看
 (9 留言) (8 反應) (0 負責人)JavaScript (5,662 star) (233 fork)batch import
beginner-friendlyenhancementhelp wanted

描述

https://developers.google.com/web/updates/2017/09/abortable-fetch

Currently it is only implemented in Firefox 57 and is coming to other browsers soon.

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

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

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

Will most likely need to implement another npm package that just include AbortController package. I found one but it also pollyfills fetch. https://github.com/mo/abortcontroller-polyfill

貢獻者指南