fetch doesn't allow for AbortSignal custom impl with constructor name other then exactly AbortSignal
See original GitHub issueMay I ask you to elaborate on the purpose of this validation?
For my use case, it is redundant. I want to pass a custom adapter from vscode.CancellationToken
to AbortSignal
:
import { AbortSignal } from "node_fetch/externals";
class CancellationSignal implements AbortSignal {
subscriptions = new WeakMap<Listener, vscode.Disposable>();
constructor(private readonly ct: vscode.CancellationToken) {}
get aborted() {
return this.ct.isCancellationRequested;
}
addEventListener(_type: "abort", listener: Listener, _opts?: unknown) {
this.subscriptions.set(listener, this.ct.onCancellationRequested(listener, this));
}
removeEventListener(_type: "abort", listener: Listener) {
this.subscriptions.get(listener)?.dispose();
}
// Some excess APIs that are not used by `node_fetch` impl
onabort = null
dispatchEvent() { return false; }
}
This is very annoying that I cannot name my class how I want. Besides that why can’t I pass a simple object literal that conforms to AbortSignal
? There is no such explicit contract that an instance of abort signal passed to fetch must be a custom class instance, since AbortSignlas
is nothing but an interface…
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (1 by maintainers)
Top Results From Across the Web
AbortSignal - Web APIs - MDN Web Docs - Mozilla
The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort ......
Read more >Errors | Node.js v19.3.0 Documentation
Most asynchronous methods that accept a callback function will accept an Error object passed as the first argument to that function. If that...
Read more >Abortable fetch - Chrome Developers
Aborting fetches using a new web primitive – The abort ... It's a new AbortSignal that mimics the signal passed to the constructor....
Read more >AbortController is your friend - Whistlr
It's to use AbortController to provide a fetch() you can abort early: ... but has a big caveat: note that AbortSignal doesn't fire...
Read more >Using fetch(), AbortSignal, And setTimeout() To Apply Retry ...
Essentially, we're going to separate the parts of the code that change at different rates. What I ended-up with was an API client...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree. This is also very annoying when you bundle and minify your code. Minifiers will change the name of your class and node-fetch will fail on that.
If somebody finds that useful - that’s fine. But having some global configuration to disable this behavior would be nice.
Closing…
symbol.toStringTag
is not…Also I took a extra peek on our
isAbortSignal
function and we also check if the name matchEventTarget
… this is weird. should remove that (but maybe not right now as it might break something, on v4 we will drop older node support when v12 goes EOL and we can start using built in AbortController provided by NodeJS.