diff --git a/src/requestNextTask.ts b/src/queueTask.ts similarity index 62% rename from src/requestNextTask.ts rename to src/queueTask.ts index 0cd9105..42a423d 100644 --- a/src/requestNextTask.ts +++ b/src/queueTask.ts @@ -1,6 +1,9 @@ const callbacks: (() => void)[] = [] -export default function requestNextTask(callback: () => void): void { +// same as queueMicrotask() but for tasks +// https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide#tasks_vs._microtasks +// https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide/In_depth#tasks_vs._microtasks +export default function queueTask(callback: () => void): void { if (callbacks.length === 0) { const channel = new MessageChannel() channel.port2.postMessage(undefined) diff --git a/src/yieldControl.ts b/src/yieldControl.ts index 0d06c74..20cf5a4 100644 --- a/src/yieldControl.ts +++ b/src/yieldControl.ts @@ -1,6 +1,6 @@ import state from './state' +import queueTask from './queueTask' import isTimeToYield from './isTimeToYield' -import requestNextTask from './requestNextTask' import hasValidContext from './hasValidContext' import { createTask, nextTask, removeTask } from './tasks' import { cancelPromiseEscape, requestPromiseEscape } from './promiseEscape' @@ -51,7 +51,7 @@ async function schedule(priority: 'user-visible' | 'background'): Promise } if (priority === 'user-visible' || typeof requestIdleCallback === 'undefined') { - await new Promise((resolve) => requestNextTask(resolve)) + await new Promise((resolve) => queueTask(resolve)) // istanbul ignore if if (navigator.scheduling?.isInputPending?.() === true) {