DEV Community

Discussion on: How to Abort a Fetch Request in JavaScript using AbortController

Collapse
 
hjorthbjorn profile image
Björn Hjorth

Can I create multiple signals from the same instance of AbortController?

Collapse
 
nas5w profile image
Nick Scialli (he/him) • Edited

I don't believe so. We're not actually creating a signal but rater we're accessing the signal property of the AbortController instance.

Edit: Here's the spec! Can confirm that the signal property is a boolean so we're really just talking one signal. You'd likely need another instance of AbortController if you're looking to potentially cancel multiple requests.

Edit 2: I could imagine, though, that you might want to cancel multiple http requests at the same time, in which case you could use the same signal to tell each fetch request to abort and that would work well.

Collapse
 
hjorthbjorn profile image
Björn Hjorth

I guess that second edit would solve most cases I can think of. Thanks for sharing.

Thread Thread
 
zhnedyalkow profile image
Zhitomir Oreshenski

Yes, I can confirm that.