【发布时间】:2020-06-20 03:56:26
【问题描述】:
我在 react native 后台计时器 setInterval 中有一个 api 调用,它会导致代码执行暂停。如果我只是在回调中做简单的事情,即使应用程序在后台,它也可以正常工作,但是如果我在回调函数中使用 await 关键字,它会暂停执行。当应用程序成为前台时,所有任务都会立即执行
const runTimer = () => {
BackgroundTimer.start();
timerInterval = BackgroundTimer.setInterval(async () => {
await callAnApi();
}, 20000);
};
const stopTimer = () => {
BackgroundTimer.clearInterval(timerInterval);
BackgroundTimer.stop();
};
【问题讨论】:
标签: react-native