main-thread-scheduling
Advanced tools
Comparing version 4.0.3 to 5.0.0
{ | ||
"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 @@ } |
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
27224
455