Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

main-thread-scheduling

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

main-thread-scheduling - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0-0

src/nextTask.d.ts

3

package.json
{
"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();
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc