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 4.0.3 to 5.0.0

2

package.json
{
"name": "main-thread-scheduling",
"version": "4.0.3",
"version": "5.0.0",
"description": "Consistently responsive apps while staying on the main thread",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -0,6 +1,16 @@

const callbacks = [];
export default function nextTask(callback) {
const channel = new MessageChannel();
channel.port2.postMessage(undefined);
// eslint-disable-next-line unicorn/prefer-add-event-listener
channel.port1.onmessage = () => callback();
if (callbacks.length === 0) {
const channel = new MessageChannel();
channel.port2.postMessage(undefined);
// eslint-disable-next-line unicorn/prefer-add-event-listener
channel.port1.onmessage = () => {
const callbacksCopy = [...callbacks];
callbacks.splice(0, callbacks.length);
for (const callback of callbacksCopy) {
callback();
}
};
}
callbacks.push(callback);
}

@@ -8,3 +8,2 @@ import nextTask from './nextTask';

nextTask(() => {
shouldRequestAnimationFrame = true;
const start = Date.now();

@@ -21,3 +20,2 @@ const deadline = start + 16;

});
shouldRequestAnimationFrame = false;
});

@@ -24,0 +22,0 @@ }

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