Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
linkedin#52: first phase of imporvement, skipped three iteration of the rFA
  • Loading branch information
SparshithNR committed Jun 22, 2017
1 parent 498efb3 commit d9bc1f0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/metal/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Engine implements EngineInterface {
private reads: Array<Function> = [];
private work: Array<Function> = [];
private running: Boolean = false;
private skipCounter: number = 4;
scheduleRead(callback: Function) {
this.reads.unshift(callback);
this.run();
Expand All @@ -28,14 +29,18 @@ export class Engine implements EngineInterface {
if (!this.running) {
this.running = true;
W.rAF(() => {
this.running = false;
for (let i = 0, rlen = this.reads.length; i < rlen; i++) {
this.reads.pop()();
}
for (let i = 0, wlen = this.work.length; i < wlen; i++) {
this.work.pop()();
if (this.skipCounter > 3) {
this.skipCounter = 0;
for (let i = 0, rlen = this.reads.length; i < rlen; i++) {
this.reads.pop()();
}
for (let i = 0, wlen = this.work.length; i < wlen; i++) {
this.work.pop()();
}
}
this.skipCounter++;
if (this.work.length > 0 || this.reads.length > 0) {
this.running = false;
this.run();
}
});
Expand Down

0 comments on commit d9bc1f0

Please sign in to comment.