BackgroundTask no longer debounces
This commit is contained in:
parent
36773bf5c0
commit
a6b6d00f49
@ -59,8 +59,7 @@ if (!global.requestIdleCallback) {
|
||||
|
||||
export function backgroundTask(fn, initialDelay = 500) {
|
||||
let id = null;
|
||||
let reRunCount = 0;
|
||||
let params = [];
|
||||
const params = [];
|
||||
|
||||
async function runTask({ didTimeout }) {
|
||||
if (didTimeout) {
|
||||
@ -69,16 +68,15 @@ export function backgroundTask(fn, initialDelay = 500) {
|
||||
}
|
||||
const start = Date.now();
|
||||
group(fn.name);
|
||||
if (params.length) {
|
||||
log(`${fn.name} params: `, ...params);
|
||||
const p = params.shift();
|
||||
if (p.length) {
|
||||
log(`${fn.name} params: `, ...p);
|
||||
}
|
||||
await fn(...params);
|
||||
await fn(...p);
|
||||
const executionTime = Date.now() - start;
|
||||
log(`${fn.name} execution time: ${executionTime}ms`);
|
||||
groupEnd(fn.name);
|
||||
params = [];
|
||||
if (reRunCount) {
|
||||
reRunCount -= 1;
|
||||
if (params.length) {
|
||||
id = requestIdleCallback(runTask);
|
||||
} else {
|
||||
id = null;
|
||||
@ -86,11 +84,10 @@ export function backgroundTask(fn, initialDelay = 500) {
|
||||
}
|
||||
|
||||
const wrapper = (...args) => {
|
||||
params.push(args);
|
||||
if (id !== null) {
|
||||
reRunCount += 1;
|
||||
return false;
|
||||
}
|
||||
params = args;
|
||||
id = requestIdleCallback(runTask);
|
||||
return true;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user