Skip to content

Commit

Permalink
refactor: remove rAF impl support
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Aug 8, 2021
1 parent 372294f commit 393a49d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
github: [aidenybai]
ko_fi: willdoescode
16 changes: 6 additions & 10 deletions src/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { VTask } from './structs';

const queue: VTask[] = [];
const stack: VTask[] = [];
const DEADLINE_THRESHOLD = 1000 / 60; // Minimum time buffer for 60 FPS
let deadline = 0;

export const schedule = (callback: VTask, important = false): void => {
if (important) {
requestAnimationFrame(callback);
} else {
queue.push(callback);
postMessage();
}
export const schedule = (callback: VTask): void => {
stack.push(callback);
postMessage();
};

const shouldYield = (): boolean =>
Expand All @@ -21,11 +17,11 @@ const shouldYield = (): boolean =>
const flush = (): void => {
deadline = performance.now() + DEADLINE_THRESHOLD;
while (!shouldYield()) {
const task = queue.shift();
const task = stack.shift();
if (task) task();
else break;
}
if (queue.length > 0) postMessage();
if (stack.length > 0) postMessage();
};

const { port1, port2 } = new MessageChannel();
Expand Down

0 comments on commit 393a49d

Please sign in to comment.