GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add support for aborting via AbortController · Issue #54 · developit/unfetch

add support for aborting via AbortController #54

New issue
Copy link
New issue
Copy link
Open
#137
#68
Open
add support for aborting via AbortController#54
#137
#68
Copy link
Labels
beginner-friendlyenhancementhelp wanted
Milestone
5.0

Description

@prabirshrestha
prabirshrestha
opened on Sep 29, 2017
Issue body actions

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

Reacted by Tejesh Mehta, Shannon Moeller 🧢, Nina Kitsu, John Schottler, Nicolás Fantone, Jafar Rezaei, Abraham Schilling and Sergey

Activity

  1. developit commented on Oct 20, 2017

    @developit
    developit
    on Oct 20, 2017
    Owner
    More actions

    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.

  2. developit
    added
    beginner-friendly
    enhancement
    help wanted
    on Oct 20, 2017
  3. prabirshrestha commented on Oct 20, 2017

    @prabirshrestha
    prabirshrestha
    on Oct 20, 2017
    Author
    More actions

    Awesome. Could you post the link to the npm package?

  4. Jador commented on Oct 30, 2017

    @Jador
    Jador
    on Oct 30, 2017
    More actions

    @prabirshrestha here's one https://www.npmjs.com/package/abortcontroller-polyfill

  5. prabirshrestha commented on Mar 22, 2018

    @prabirshrestha
    prabirshrestha
    on Mar 22, 2018
    Author
    More actions

    Chrome 66 beta seems to officially support it. https://blog.chromium.org/2018/03/chrome-66-beta-css-typed-object-model.html

  6. simonbuerger
    added a commit that references this issue on Apr 17, 2018

    Add support for AbortController (developit#54)

    ebec172
  7. lxsmnsyc commented on Apr 12, 2019

    @lxsmnsyc
    lxsmnsyc
    on Apr 12, 2019
    More actions

    An implementation of WHATWG AbortController interface.

    https://github.com/mysticatea/abort-controller

  8. dangdennis commented on Nov 10, 2019

    @dangdennis
    dangdennis
    on Nov 10, 2019
    More actions

    As of 2019, https://caniuse.com/#search=abort AbortController is supported by 86% of browser users. But I'm not sure if AbortController is available for use with XMLHttpRequest. But there's an alternative since that req object already has an .abort API.

    So perhaps there can be a way expose the request's XMLHttpRequest.abort method to the caller from the promise wrapper. Although I'm unsure how you'd return that in the context of a Promise since resolve is only allowed to be called once. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/abort

    Edit:
    Nevermind, someone already solved it using event emitters.
    https://codesandbox.io/s/92vnjok08r

  9. JohnnyFun commented on Jan 10, 2020

    @JohnnyFun
    JohnnyFun
    on Jan 10, 2020
    More actions

    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
  10. nfantone commented on Feb 11, 2020

    @nfantone
    nfantone
    on Feb 11, 2020
    More actions

    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
  11. developit
    added this to the 5.0 milestone on Sep 29, 2020
  12. mikestopcontinues commented on Nov 30, 2020

    @mikestopcontinues
    mikestopcontinues
    on Nov 30, 2020
    More actions

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    beginner-friendlyenhancementhelp wanted

    Projects

    No projects

      Milestone

      • 5.0No due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.