fable-compiler / fable-fetch

Fable bindings for Browsers' Fetch API
MIT License
17 stars 8 forks source link

Add signal to RequestProperties #3

Open sWW26 opened 5 years ago

sWW26 commented 5 years ago

I wanted to be able to abort fetches while using these bindings but realised it doesn't have support for the signal property. I made a start at implementing it however I realised its AbortController hasn't been implemented in Node.js as far as I can tell so isn't possible to test it. Does this browser specific binding belong in this library or are you trying to keep it as generic as possible? If it doesn't belong here what would be a good approach to making it available to use?

https://developer.mozilla.org/en-US/docs/Web/API/AbortController

whitetigle commented 5 years ago

Hi, while I don't have an answer myself regarding the fable-fetch goals, I have been using request-promise for a while on Node.js 10.x which seems to allow an abort mechanism. (https://github.com/request/request-promise/issues/85). Is that what you're looking for?

alfonsogarciacaro commented 5 years ago

As far as I know, the fetch API is not supported natively in node.js and you need a library for it. node-fetch at least seems to support AbortController (using another library): https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal

Maybe you could create a package for AbortController and add a dependency to it here. You can also PR to fable-browser to add such a package.

Thinking about this and compatibility with node.js, this library assumes that fetch is a global value. Maybe we should make it easier for users to define an imported module like node-fetch instead.