Skip to content

Commit

Permalink
RN: Change Time Drift Error into Warning
Browse files Browse the repository at this point in the history
Summary: Changes the time drift error into a warning that will only get logged once per debugging session.

Reviewed By: jingc

Differential Revision: D3539067

fbshipit-source-id: 357db15750d867a91c39b5fc5fd6ed4ae2852bc7
  • Loading branch information
yungsters authored and bubblesunyum committed Aug 23, 2016
1 parent 3413a74 commit 9550935
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var performanceNow = require('fbjs/lib/performanceNow');
var warning = require('fbjs/lib/warning');
var Systrace = require('Systrace');

let hasEmittedTimeDriftWarning = false;

/**
* JS implementation of timer functions. Must be completely driven by an
* external clock signal, all that's stored here is timerID, timer type, and
Expand Down Expand Up @@ -147,6 +149,17 @@ var JSTimersExecution = {
}
},

/**
* Called from native (in development) when environment times are out-of-sync.
*/
emitTimeDriftWarning: function(warningMessage) {
if (hasEmittedTimeDriftWarning) {
return;
}
hasEmittedTimeDriftWarning = true;
console.warn(warningMessage);
},

_clearIndex: function(i) {
JSTimersExecution.timerIDs[i] = null;
JSTimersExecution.callbacks[i] = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
public interface JSTimersExecution extends JavaScriptModule {

public void callTimers(WritableArray timerIDs);

public void emitTimeDriftWarning(String warningMessage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,10 @@ public void createTimer(
if (mDevSupportManager.getDevSupportEnabled()) {
long driftTime = Math.abs(remoteTime - deviceTime);
if (driftTime > 60000) {
throw new RuntimeException(
"Debugger and device times have drifted by more than 60s." +
"Please correct this by running adb shell " +
"\"date `date +%m%d%H%M%Y.%S`\" on your debugger machine."
);
getReactApplicationContext().getJSModule(executorToken, JSTimersExecution.class)
.emitTimeDriftWarning(
"Debugger and device times have drifted by more than 60s. Please correct this by " +
"running adb shell \"date `date +%m%d%H%M%Y.%S`\" on your debugger machine.");
}
}

Expand Down

0 comments on commit 9550935

Please sign in to comment.