Skip to content

Instantly share code, notes, and snippets.

@annevk
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annevk/56e97115f2c9c2e90c23 to your computer and use it in GitHub Desktop.
Save annevk/56e97115f2c9c2e90c23 to your computer and use it in GitHub Desktop.
Controlling a fetch

A Request object is needed to fetch. A Response object is the result. fetch() starts the process. How do we control it?

  1. fetch(req); req.abort()
  2. var f = fetch(req); f.abort() (subclassing promises seems to clash with upcoming async/await syntax)
  3. fetch(req, handle(a) { a() })
  4. fetch(req, { control:true }).then(con) { con.abort() } (fetch() would resolve immediately; control object would also have con.response or some such returning a promise)
  5. var c = req.send(); c.abort() } (get the control object synchronously)
  6. fetchRegistry.last.abort() (have some kind of global registry for all fetches made within the environment)
@wanderview
Copy link

  1. fetch(req).abort() but with an attribute to the response promise like fetch(req).ready.then().

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