main-thread-scheduling
Advanced tools
Comparing version 3.0.0 to 4.0.0-0
{ | ||
"name": "main-thread-scheduling", | ||
"version": "3.0.0", | ||
"version": "4.0.0-0", | ||
"description": "Consistently responsive apps while staying on the main thread", | ||
@@ -8,2 +8,3 @@ "license": "MIT", | ||
"funding": "https://github.com/sponsors/astoilkov", | ||
"homepage": "https://github.com/astoilkov/main-thread-scheduling", | ||
"author": { | ||
@@ -10,0 +11,0 @@ "name": "Antonio Stoilkov", |
@@ -72,3 +72,3 @@ <br> | ||
Note: If you want to understand how this library works under the hook and some of the details – read the [in-depth](./docs/in-depth-overview.md) doc. | ||
If you want to understand how this library works under the hook and some of the details – read the [in-depth](./docs/in-depth-overview.md) doc. | ||
@@ -75,0 +75,0 @@ #### `yieldOrContinue(priority: 'background' | 'user-visible')` |
// #hack | ||
let shouldRequestAnimationFrame = false; | ||
const idlePhaseTracker = createPhaseTracker((callback) => { | ||
if (typeof requestIdleCallback === 'undefined') { | ||
return; | ||
} | ||
const handleIdleCallback = () => { | ||
@@ -5,0 +8,0 @@ requestIdleCallback((deadline) => { |
@@ -0,1 +1,2 @@ | ||
import nextTask from './nextTask'; | ||
import waitCallback from './waitCallback'; | ||
@@ -17,25 +18,20 @@ import isTimeToYield from './isTimeToYield'; | ||
async function schedule(priority) { | ||
if (priority === 'user-visible') { | ||
await promiseSequantial([ | ||
() => waitCallback(requestLaterMicrotask), | ||
() => waitCallback(requestIdleCallback, { | ||
// #WET 2021-06-05T3:07:18+03:00 | ||
// #connection 2021-06-05T3:07:18+03:00 | ||
// call at least once per frame | ||
// asuming 60 fps, 1000/60 = 16.667 | ||
timeout: 16, | ||
}), | ||
]); | ||
if (typeof requestIdleCallback === 'undefined') { | ||
await waitCallback(requestAnimationFrame); | ||
await waitCallback(nextTask); | ||
} | ||
else if (priority === 'user-visible') { | ||
await waitCallback(requestLaterMicrotask); | ||
await waitCallback(requestIdleCallback, { | ||
// #WET 2021-06-05T3:07:18+03:00 | ||
// #connection 2021-06-05T3:07:18+03:00 | ||
// call at least once per frame | ||
// assuming 60 fps, 1000/60 = 16.667 | ||
timeout: 16, | ||
}); | ||
} | ||
else { | ||
await promiseSequantial([ | ||
() => waitCallback(requestLaterMicrotask), | ||
() => waitCallback(requestIdleCallback), | ||
]); | ||
await waitCallback(requestLaterMicrotask); | ||
await waitCallback(requestIdleCallback); | ||
} | ||
} | ||
async function promiseSequantial(getPromises) { | ||
for (const getPromise of getPromises) { | ||
await getPromise(); | ||
} | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
26272
22
427