3 ms·
I have been waiting for cancellable promises for a while primarily for cancelling long lasting fetch requests which is a very common thing to need. (Not really
by daleharvey 10y ago
I have been waiting for cancellable promises for a while primarily for cancelling long lasting fetch requests which is a very common thing to need.
(Not really sure how to parse non determinism and throwing being related to cancelling promises)
- fareesh 10y agoWhat's a good existing way to deal with this use-case? Is there a useful library that wraps setTimeout / other logic to determine the quality of a user's internet connection in case of very poor connectivity (2G etc) ?
- fermuch 10y agoIn react native, NetInfo has an api to detect network changes and I use that to stop all my setIntervals and start again with a different set of args, including wait time before calling again.
- jdesjean 10y agoThe way to handle this case is to use Promise.race with 2 promises. The first promise is your logic. The second promise is rejected after a timeout. For more detail read the section "never calling the callback" from "you don't know js" book on "async" in chapter 3 https://github.com/getify/You-Dont-Know-JS/blob/master/async%20%26%20performance/ch3.md https://github.com/getify/You-Dont-Know-JS/blob/master/async...
- fareesh 10y agoThanks I'll check it out
- soft_dev_person 10y agoBut that doesn't actually cancel the request, and thusly the data is downloaded anyway? Or am I missing something?