I am building a React Native/Expo App and I am using a lexicon module (https://github.com/peterolson/chinese-lexicon) which fetches some big files and does some heavy transformations, so it takes about 10-15 seconds to load. While loading the module, the whole app freezes.
I know that there is no multithreading in Javascript - but there has to be a way to do some heavier processing without blocking the UI, right? Where/how do I load this module without making my app freeze?
I tried to edit the module and make it return a Promise which resolves as soon as the Lexicon is loaded:
function load() {
return new Promise((Resolve, reject) => {
//All the code from the module
//Calling Resolve with the loaded lexicon
}
}
module.exports = { load }
Now I am loading the lexicon like this: require('chinese-lexicon').load().then((lexicon) => { ... });, however it is still blocking the main thread - which makes sense, as the Promise executor function itself is still running synchronously.
I also tried some tricks like using setTimeout(() => { ... }, 0) in the Promise executor function, but it's still blocking.