Skip to content

Commit

Permalink
🐜 ♻️ rename requestNextTask() β†’ queueTask()
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Aug 23, 2023
1 parent 16bb4b5 commit 3b3ba08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/requestNextTask.ts β†’ src/queueTask.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/yieldControl.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -51,7 +51,7 @@ async function schedule(priority: 'user-visible' | 'background'): Promise<void>
}

if (priority === 'user-visible' || typeof requestIdleCallback === 'undefined') {
await new Promise<void>((resolve) => requestNextTask(resolve))
await new Promise<void>((resolve) => queueTask(resolve))

// istanbul ignore if
if (navigator.scheduling?.isInputPending?.() === true) {
Expand Down

0 comments on commit 3b3ba08

Please sign in to comment.