@tamagui/react-native-web-lite
Version:
React Native for Web
54 lines (53 loc) • 1.79 kB
JavaScript
import infoLog from "../infoLog";
var JSEventLoopWatchdog = {
getStats: function () {
return {
stallCount,
totalStallTime,
longestStall,
acceptableBusyTime
};
},
reset: function () {
infoLog("JSEventLoopWatchdog: reset"), totalStallTime = 0, stallCount = 0, longestStall = 0, lastInterval = window.performance.now();
},
addHandler: function (handler) {
handlers.push(handler);
},
install: function (param) {
var {
thresholdMS
} = param;
if (acceptableBusyTime = thresholdMS, installed) return;
installed = !0, lastInterval = window.performance.now();
function iteration() {
var now = window.performance.now(),
busyTime = now - lastInterval;
if (busyTime >= thresholdMS) {
var stallTime = busyTime - thresholdMS;
stallCount++, totalStallTime += stallTime, longestStall = Math.max(longestStall, stallTime);
var msg = `JSEventLoopWatchdog: JS thread busy for ${busyTime}ms. ${totalStallTime}ms in ${stallCount} stalls so far. `;
handlers.forEach(function (handler) {
msg += handler.onStall({
lastInterval,
busyTime
}) || "";
}), infoLog(msg);
}
handlers.forEach(function (handler) {
handler.onIterate && handler.onIterate();
}), lastInterval = now, setTimeout(iteration, thresholdMS / 5);
}
iteration();
}
},
acceptableBusyTime = 0,
installed = !1,
totalStallTime = 0,
stallCount = 0,
longestStall = 0,
lastInterval = 0,
handlers = [],
JSEventLoopWatchdog_default = JSEventLoopWatchdog;
export { JSEventLoopWatchdog_default as default };
//# sourceMappingURL=index.native.js.map