Split immediate into multiple passes

Reviewed By: tadeuzagallo

Differential Revision: D2663957

fb-gh-sync-id: d7f0041fc98edb46e518f684527effe2f5201240
This commit is contained in:
Milen Dzhumerov 2015-11-19 03:30:45 -08:00 committed by facebook-github-bot-3
parent a3d9f5ba84
commit c8fd9f7588
1 changed files with 25 additions and 3 deletions

View File

@ -14,6 +14,7 @@ var invariant = require('invariant');
var keyMirror = require('keyMirror'); var keyMirror = require('keyMirror');
var performanceNow = require('performanceNow'); var performanceNow = require('performanceNow');
var warning = require('warning'); var warning = require('warning');
var BridgeProfiling = require('BridgeProfiling');
/** /**
* JS implementation of timer functions. Must be completely driven by an * JS implementation of timer functions. Must be completely driven by an
@ -107,15 +108,36 @@ var JSTimersExecution = {
} }
}, },
/**
* Performs a single pass over the enqueued immediates. Returns whether
* more immediates are queued up (can be used as a condition a while loop).
*/
callImmediatesPass: function() {
BridgeProfiling.profile('JSTimersExecution.callImmediatesPass()');
// The main reason to extract a single pass is so that we can track
// in the system trace
if (JSTimersExecution.immediates.length > 0) {
var passImmediates = JSTimersExecution.immediates.slice();
JSTimersExecution.immediates = [];
passImmediates.forEach((timerID) => {
JSTimersExecution.callTimer(timerID);
});
}
BridgeProfiling.profileEnd();
return JSTimersExecution.immediates.length > 0;
},
/** /**
* This is called after we execute any command we receive from native but * This is called after we execute any command we receive from native but
* before we hand control back to native. * before we hand control back to native.
*/ */
callImmediates: function() { callImmediates: function() {
JSTimersExecution.errors = null; JSTimersExecution.errors = null;
while (JSTimersExecution.immediates.length !== 0) { while (JSTimersExecution.callImmediatesPass()) {}
JSTimersExecution.callTimer(JSTimersExecution.immediates.shift());
}
if (JSTimersExecution.errors) { if (JSTimersExecution.errors) {
JSTimersExecution.errors.forEach((error) => JSTimersExecution.errors.forEach((error) =>
require('JSTimers').setTimeout(() => { throw error; }, 0) require('JSTimers').setTimeout(() => { throw error; }, 0)