0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-16 03:58:20 -05:00
penpot/frontend/text-editor/editor/controllers/SafeGuard.js
2024-11-19 17:05:30 +01:00

34 lines
511 B
JavaScript

/**
* Max. amount of time we should allow.
*
* @type {number}
*/
const SAFE_GUARD_TIME = 1000;
/**
* Time at which the safeguard started.
*
* @type {number}
*/
let startTime = Date.now();
/**
* Marks the start of the safeguard.
*/
export function start() {
startTime = Date.now();
}
/**
* Checks if the safeguard should throw.
*/
export function update() {
if (Date.now - startTime >= SAFE_GUARD_TIME) {
throw new Error('Safe guard timeout');
}
}
export default {
start,
update,
}