GeezerVison is showing github.com — add support for aborting via AbortController · Issue #54 · developit/unfetch
add support for aborting via AbortController #54Descriptionhttps://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 Reacted by Tejesh Mehta, Shannon Moeller 🧢, Nina Kitsu, John Schottler, Nicolás Fantone, Jafar Rezaei, Abraham Schilling and Sergey Activitydevelopit commented on Oct 20, 2017 So we'd need a new npm package that exports a standalone polyfill for AbortController, and then the only modifications needed to unfetch would be to proxy signal.onabort = request.abort. Seems like it might be doable in a few bytes. prabirshrestha commented on Oct 20, 2017 Awesome. Could you post the link to the npm package? Jador commented on Oct 30, 2017 prabirshrestha commented on Mar 22, 2018 lxsmnsyc commented on Apr 12, 2019 dangdennis commented on Nov 10, 2019 JohnnyFun commented on Jan 10, 2020 You could also just add an abort function on the returned promise. Hacky, but works.
function unfetch(url, options) {
options = options || {};
const request = new XMLHttpRequest();
const task = new Promise((resolve, reject) => {
...
});
task.abort = () => request.abort() // lol
return task
}
Reacted by Jafar Rezaei Reacted by Abraham Schilling nfantone commented on Feb 11, 2020 Any movements on this? With all major green browsers supporting it, AbortController is steadily becoming the norm with many sources and docs out there showing people how to use it. Would be nice to have it baked into unfetch. Reacted by Christian Todd mikestopcontinues commented on Nov 30, 2020 node-fetch is actively recommending abort-controller. At least one of the PRs will bring support. What's preventing movement on this? What's everyone using in the meantime?
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|