In React Native, we use AppState to check app is in active or background or something. What I want to do is when appState eventListener is catch that app is going background, execute some async function.
But when that moment, non-async function is executed and async function is not executed and back to foreGround(active), that async function is executed.
Maybe cause JavaScript Event Loop, that async function is buffered in a queue and executed in the foreground.
What could I do for executing instantly?
const listener = AppState.addEventListener('change', (state) => {
let timeout;
if (state === 'background') {
asyncFunction();
}
})