Skip to content

Commit

Permalink
async execution of next set of phases
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 18, 2019
1 parent 0af6175 commit fcebc09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
17 changes: 13 additions & 4 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,17 @@
executeQueue.shift(); // If there is new data in the execution queue, continue to it.

if (executeQueue.length !== 0) {
executeNext();
if (performance.now() - executeStart >= 16) {
// If the current frame doesn't have sufficient time left to keep
// running then start the next execution in the next frame.
requestAnimationFrame(function () {
executeStart = performance.now();
executeNext();
});
} else {
executeStart = performance.now();
executeNext();
}
}
}
/**
Expand All @@ -944,9 +954,7 @@

function executeNext() {
// Get the next data update.
var dataNew = executeQueue[0]; // Record the current time to reference when running different functions.

executeStart = performance.now(); // Merge new data into current data.
var dataNew = executeQueue[0]; // Merge new data into current data.

for (var key in dataNew) {
data[key] = dataNew[key];
Expand Down Expand Up @@ -988,6 +996,7 @@
executeQueue.push(dataNew); // Execute the next function in the queue if none are scheduled yet.

if (executeQueue.length === 1) {
executeStart = performance.now();
executeNext();
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/moon/dist/moon.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions packages/moon/src/executor/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,19 @@ function executePatch(patches) {

// If there is new data in the execution queue, continue to it.
if (executeQueue.length !== 0) {
executeNext();
if (performance.now() - executeStart >= 16) {
// If the current frame doesn't have sufficient time left to keep
// running then start the next execution in the next frame.
requestAnimationFrame(() => {
executeStart = performance.now();

executeNext();
});
} else {
executeStart = performance.now();

executeNext();
}
}
}

Expand All @@ -358,9 +370,6 @@ function executeNext() {
// Get the next data update.
const dataNew = executeQueue[0];

// Record the current time to reference when running different functions.
executeStart = performance.now();

// Merge new data into current data.
for (let key in dataNew) {
data[key] = dataNew[key];
Expand Down Expand Up @@ -402,6 +411,8 @@ export function execute(dataNew) {

// Execute the next function in the queue if none are scheduled yet.
if (executeQueue.length === 1) {
executeStart = performance.now();

executeNext();
}
}

0 comments on commit fcebc09

Please sign in to comment.