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