Skip to content

Commit

Permalink
Re-name scheduledCallback -> scheduledHostCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed Oct 9, 2018
1 parent 4b08d45 commit 2352424
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/scheduler/src/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ if (typeof window !== 'undefined' && window._schedMock) {
}
}

var scheduledCallback = null;
var scheduledHostCallback = null;
var isIdleScheduled = false;
var timeoutTime = -1;

Expand Down Expand Up @@ -566,13 +566,18 @@ if (typeof window !== 'undefined' && window._schedMock) {

isIdleScheduled = false;

var prevScheduledCallback = scheduledHostCallback;
var prevTimeoutTime = timeoutTime;
scheduledHostCallback = null;
timeoutTime = -1;

var currentTime = getCurrentTime();

var didTimeout = false;
if (frameDeadline - currentTime <= 0) {
// There's no time left in this idle period. Check if the callback has
// a timeout and whether it's been exceeded.
if (timeoutTime !== -1 && timeoutTime <= currentTime) {
if (prevTimeoutTime !== -1 && prevTimeoutTime <= currentTime) {
// Exceeded the timeout. Invoke the callback even though there's no
// time left.
didTimeout = true;
Expand All @@ -584,17 +589,16 @@ if (typeof window !== 'undefined' && window._schedMock) {
requestAnimationFrameWithTimeout(animationTick);
}
// Exit without invoking the callback.
scheduledHostCallback = prevScheduledCallback;
timeoutTime = prevTimeoutTime;
return;
}
}

timeoutTime = -1;
var callback = scheduledCallback;
scheduledCallback = null;
if (callback !== null) {
if (prevScheduledCallback !== null) {
isPerformingIdleWork = true;
try {
callback(didTimeout);
prevScheduledCallback(didTimeout);
} finally {
isPerformingIdleWork = false;
}
Expand All @@ -605,7 +609,7 @@ if (typeof window !== 'undefined' && window._schedMock) {
window.addEventListener('message', idleTick, false);

var animationTick = function(rafTime) {
if (scheduledCallback !== null) {
if (scheduledHostCallback !== null) {
// Eagerly schedule the next animation callback at the beginning of the
// frame. If the scheduler queue is not empty at the end of the frame, it
// will continue flushing inside that callback. If the queue *is* empty,
Expand Down Expand Up @@ -651,7 +655,7 @@ if (typeof window !== 'undefined' && window._schedMock) {
};

requestHostCallback = function(callback, absoluteTimeout) {
scheduledCallback = callback;
scheduledHostCallback = callback;
timeoutTime = absoluteTimeout;
if (isPerformingIdleWork || absoluteTimeout < 0) {
// Don't wait for the next frame. Continue working ASAP, in a new event.
Expand All @@ -667,7 +671,7 @@ if (typeof window !== 'undefined' && window._schedMock) {
};

cancelHostCallback = function() {
scheduledCallback = null;
scheduledHostCallback = null;
isIdleScheduled = false;
timeoutTime = -1;
};
Expand Down

0 comments on commit 2352424

Please sign in to comment.