5 ms·
Nice to see Promise.race() in there. I've used it to emulate timeout logic on I/O functionality. Useful when your JS is operating in an environment where there'
by billmalarky 6y ago
Nice to see Promise.race() in there. I've used it to emulate timeout logic on I/O functionality. Useful when your JS is operating in an environment where there's a timeout constraint you can't control and you want your JS to gracefully handle timing out instead of the script just being killed.
Example use case is a background job running in JS via React Native. iOS limits these jobs to 30 seconds then kills the script. Promise.race() is one way to regain control of the thread and begin teardown prior to iOS killing the script, if for example the other promise is hanging past 30 seconds. Keep in mind this is not a true timeout, the other promise will continue to try to resolve until script is terminated.
https://github.com/billmalarky/react-native-queue/blob/5c45bf92a6c24275feb753cc95366e74c754a956/Models/Worker.js#L86-L125 https://github.com/billmalarky/react-native-queue/blob/5c45b...