let impl;
function initRunOnBackgroundDelay() {
    return (impl = {
        delayedBackgroundFunctionArray: [],
        clearDelayedBackgroundFunctions,
        delayRunOnBackground,
        runDelayedBackgroundFunctions,
    });
}
function delayRunOnBackground(fnObj, task) {
    impl.delayedBackgroundFunctionArray.push({ task });
    const delayIndices = fnObj._delayIndices ??= [];
    delayIndices.push(impl.delayedBackgroundFunctionArray.length - 1);
}
function clearDelayedBackgroundFunctions() {
    impl.delayedBackgroundFunctionArray.length = 0;
}
function runDelayedBackgroundFunctions() {
    for (const details of impl.delayedBackgroundFunctionArray) {
        if (details?.jsFnHandle) {
            details.task(details.jsFnHandle._jsFnId, details.jsFnHandle._execId);
        }
    }
    clearDelayedBackgroundFunctions();
}
export { initRunOnBackgroundDelay };
//# sourceMappingURL=delayRunOnBackground.js.map