perf: optimize device & alarm query

This commit is contained in:
yangsy
2025-09-12 11:19:22 +08:00
parent e74d04d24b
commit 2ddab88a92
3 changed files with 35 additions and 6 deletions

20
src/utils/run-task.ts Normal file
View File

@@ -0,0 +1,20 @@
export const runTask = (task: () => void) => {
// 方案一rIC
requestIdleCallback((idle) => {
if (idle.timeRemaining() > 0) {
task();
} else {
runTask(task);
}
});
// 方案二rAF + 时间判断
// const start = Date.now();
// requestAnimationFrame(() => {
// const now = Date.now();
// if (now - start > 16.6) {
// task();
// } else {
// runTask(task);
// }
// });
};