DEV Community

Discussion on: Clean Up Async Requests in `useEffect` Hooks

Collapse
 
prberg profile image
Paul Berg

Great article! However I don't see why you couldn't use the AbortController even if you're not using fetch. You'd just check for the abortController.signal.aborted flag in whatever resolve or reject block you get from the Promise.

Collapse
 
pallymore profile image
Yurui Zhang

Thanks - yes that's possible - however in that case the AbortController instance basically acts like a boolean flag. 😅

it can be helpful in certain scenarios though. if you are working with a lot of Promises - I'd recommend checking out npmjs.com/package/cancelable-promise

Collapse
 
prberg profile image
Paul Berg

Whoah, that library looks like just what I was looking for. Thanks!