main-thread-scheduling
Advanced tools
Comparing version 8.0.0 to 9.0.0
@@ -1,4 +0,6 @@ | ||
import yieldControl from './src/yieldControl'; | ||
import isTimeToYield from './src/isTimeToYield'; | ||
import yieldOrContinue from './src/yieldOrContinue'; | ||
export { yieldOrContinue, yieldControl, isTimeToYield }; | ||
export { default as yieldOrContinue } from './src/yieldOrContinue'; | ||
export { default as yieldControl } from './src/yieldControl'; | ||
export { default as isTimeToYield } from './src/isTimeToYield'; | ||
export { default as Deferred } from './src/Deferred'; | ||
export { default as queueTask } from './src/queueTask'; | ||
export { default as afterFrame } from './src/afterFrame'; |
13
index.js
@@ -1,4 +0,9 @@ | ||
import yieldControl from './src/yieldControl'; | ||
import isTimeToYield from './src/isTimeToYield'; | ||
import yieldOrContinue from './src/yieldOrContinue'; | ||
export { yieldOrContinue, yieldControl, isTimeToYield }; | ||
// primary | ||
export { default as yieldOrContinue } from './src/yieldOrContinue'; | ||
// secondary | ||
export { default as yieldControl } from './src/yieldControl'; | ||
export { default as isTimeToYield } from './src/isTimeToYield'; | ||
// utility | ||
export { default as Deferred } from './src/Deferred'; | ||
export { default as queueTask } from './src/queueTask'; | ||
export { default as afterFrame } from './src/afterFrame'; |
{ | ||
"name": "main-thread-scheduling", | ||
"version": "8.0.0", | ||
"version": "9.0.0", | ||
"description": "Fast and consistently responsive apps using a single function call", | ||
@@ -70,3 +70,6 @@ "license": "MIT", | ||
"typescript": "^4.7.3" | ||
}, | ||
"dependencies": { | ||
"p-is-promise": "^4.0.0" | ||
} | ||
} |
@@ -22,3 +22,3 @@ <br> | ||
<a href="https://github.com/astoilkov/main-thread-scheduling/actions/workflows/main.yml"> | ||
<img src="https://img.shields.io/github/workflow/status/astoilkov/main-thread-scheduling/CI" alt="Build Status" /> | ||
<img src="https://img.shields.io/github/actions/workflow/status/astoilkov/main-thread-scheduling/main.yml?branch=main" alt="Build Status" /> | ||
</a> | ||
@@ -25,0 +25,0 @@ <p> |
import { Task } from './tasks'; | ||
import { WhenReady } from './whenReady'; | ||
import Deferred from './Deferred'; | ||
declare type State = { | ||
tasks: Task[]; | ||
frameTimeElapsed: boolean; | ||
onIdleCallback: WhenReady<void>; | ||
onAnimationFrame: WhenReady<void>; | ||
onIdleCallback: Deferred; | ||
onAnimationFrame: Deferred; | ||
frameWorkStartTime: number | undefined; | ||
@@ -9,0 +9,0 @@ idleDeadline: IdleDeadline | undefined; |
@@ -1,2 +0,2 @@ | ||
import whenReady from './whenReady'; | ||
import Deferred from './Deferred'; | ||
const state = { | ||
@@ -6,6 +6,6 @@ tasks: [], | ||
frameTimeElapsed: false, | ||
onIdleCallback: whenReady(), | ||
onAnimationFrame: whenReady(), | ||
onIdleCallback: new Deferred(), | ||
onAnimationFrame: new Deferred(), | ||
frameWorkStartTime: undefined, | ||
}; | ||
export default state; |
@@ -0,5 +1,5 @@ | ||
import Deferred from './Deferred'; | ||
export declare type Task = { | ||
priority: 'background' | 'user-visible'; | ||
ready: Promise<void>; | ||
resolve: () => void; | ||
deferred: Deferred; | ||
}; | ||
@@ -6,0 +6,0 @@ /** |
@@ -1,3 +0,3 @@ | ||
import whenReady from './whenReady'; | ||
import state from './state'; | ||
import Deferred from './Deferred'; | ||
import { startTracking } from './tracking'; | ||
@@ -9,7 +9,6 @@ /** | ||
export function createTask(priority) { | ||
const wr = whenReady(); | ||
const item = { priority, ready: wr.promise, resolve: wr.resolve }; | ||
const item = { priority, deferred: new Deferred() }; | ||
const insertIndex = priority === 'user-visible' | ||
? 0 | ||
: state.tasks.findIndex((deferred) => deferred.priority === 'user-visible'); | ||
: state.tasks.findIndex((task) => task.priority === 'user-visible'); | ||
state.tasks.splice(insertIndex === -1 ? 0 : insertIndex, 0, item); | ||
@@ -43,4 +42,4 @@ if (state.tasks.length === 1) { | ||
if (task !== undefined) { | ||
task.resolve(); | ||
task.deferred.resolve(); | ||
} | ||
} |
import state from './state'; | ||
import whenReady from './whenReady'; | ||
import Deferred from './Deferred'; | ||
let isTracking = false; | ||
@@ -22,3 +22,3 @@ let idleCallbackId; | ||
state.onIdleCallback.resolve(); | ||
state.onIdleCallback = whenReady(); | ||
state.onIdleCallback = new Deferred(); | ||
}); | ||
@@ -29,3 +29,3 @@ } | ||
state.onAnimationFrame.resolve(); | ||
state.onAnimationFrame = whenReady(); | ||
state.onAnimationFrame = new Deferred(); | ||
if (state.tasks.length === 0) { | ||
@@ -32,0 +32,0 @@ isTracking = false; |
import state from './state'; | ||
import queueTask from './queueTask'; | ||
import isTimeToYield from './isTimeToYield'; | ||
import requestNextTask from './requestNextTask'; | ||
import hasValidContext from './hasValidContext'; | ||
@@ -26,3 +26,3 @@ import { createTask, nextTask, removeTask } from './tasks'; | ||
if (state.tasks[0] !== task) { | ||
await task.ready; | ||
await task.deferred; | ||
if (isTimeToYield(priority)) { | ||
@@ -41,6 +41,6 @@ await schedule(priority); | ||
if (state.frameTimeElapsed) { | ||
await state.onAnimationFrame.promise; | ||
await state.onAnimationFrame; | ||
} | ||
if (priority === 'user-visible' || typeof requestIdleCallback === 'undefined') { | ||
await new Promise((resolve) => requestNextTask(resolve)); | ||
await new Promise((resolve) => queueTask(resolve)); | ||
// istanbul ignore if | ||
@@ -55,3 +55,3 @@ if (((_b = (_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending) === null || _b === void 0 ? void 0 : _b.call(_a)) === true) { | ||
else { | ||
await state.onIdleCallback.promise; | ||
await state.onIdleCallback; | ||
// not checking for `navigator.scheduling?.isInputPending?.()` here because idle callbacks | ||
@@ -58,0 +58,0 @@ // ensure no input is pending |
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
28159
30
475
1
+ Addedp-is-promise@^4.0.0
+ Addedp-is-promise@4.0.0(transitive)