main-thread-scheduling
Advanced tools
Comparing version 14.1.1 to 14.2.0
{ | ||
"name": "main-thread-scheduling", | ||
"version": "14.1.1", | ||
"version": "14.2.0", | ||
"description": "Fast and consistently responsive apps using a single function call", | ||
@@ -35,3 +35,7 @@ "license": "MIT", | ||
"worker", | ||
"web worker" | ||
"web worker", | ||
"Core Web Vitals", | ||
"INP", | ||
"Interaction to Next Paint", | ||
"performance" | ||
], | ||
@@ -38,0 +42,0 @@ "module": "index.js", |
@@ -36,2 +36,3 @@ <br> | ||
- Your users' computer fans don't spin. | ||
- Your [INP (Interaction to Next Paint)](https://web.dev/articles/inp) is in green. | ||
- It's easy to plug it into your existing codebase. | ||
@@ -38,0 +39,0 @@ |
@@ -15,18 +15,19 @@ import ricTracker from './ricTracker'; | ||
canWorkMore(task) { | ||
const isInputPending = navigator.scheduling?.isInputPending?.() === true; | ||
return !isInputPending && this.#calculateDeadline(task) - Date.now() > 0; | ||
return !this.#isInputPending() && this.#calculateDeadline(task) - Date.now() > 0; | ||
} | ||
async nextWorkCycle(task) { | ||
if (task.type === 'frame-based') { | ||
await Promise.race([frameTracker.waitAfterFrame(), waitHiddenTask()]); | ||
} | ||
else if (task.type === 'idle-based') { | ||
if (ricTracker.available) { | ||
await ricTracker.waitIdleCallback(); | ||
do { | ||
if (task.type === 'frame-based') { | ||
await Promise.race([frameTracker.waitAfterFrame(), waitHiddenTask()]); | ||
} | ||
else { | ||
// todo: use waitHiddenTask() with a timeout | ||
await frameTracker.waitAfterFrame(); | ||
else if (task.type === 'idle-based') { | ||
if (ricTracker.available) { | ||
await ricTracker.waitIdleCallback(); | ||
} | ||
else { | ||
// todo: use waitHiddenTask() with a timeout | ||
await frameTracker.waitAfterFrame(); | ||
} | ||
} | ||
} | ||
} while (this.#isInputPending()); | ||
this.#workCycleStart = Date.now(); | ||
@@ -50,2 +51,5 @@ } | ||
} | ||
#isInputPending() { | ||
return navigator.scheduling?.isInputPending?.() === true; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31770
563
150