Skip to content

Instantly share code, notes, and snippets.

@joehonton
Created June 18, 2022 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehonton/8c688c27476ee3e7f1229db104eff7ef to your computer and use it in GitHub Desktop.
Save joehonton/8c688c27476ee3e7f1229db104eff7ef to your computer and use it in GitHub Desktop.
function computeLayout(idleDeadline) {
var milliseconds = idleDeadline.timeRemaining();
var haltTime = performance.now() + milliseconds;
for (let i=lastIndex; i < queue.length; i++) {
if (performance.now() > haltTime)
break;
// pseudocode
x = R cosΦ sin(λ - λ₀)
y = R (cosΦ₀ sinΦ - sinΦ₀ cosΦ cos(λ - λ₀))
lastIndex = i;
}
// if not complete, ask for another notification
if (lastIndex < queue.length-1)
idleCallbackId = requestIdleCallback(computeLayout);
else
idleCallbackId = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment