UNPKG

scrivito

Version:

Scrivito is a professional, yet easy to use SaaS Enterprise Content Management Service, built for digital agencies and medium to large businesses. It is completely maintenance-free, cost-effective, and has unprecedented performance and security.

35 lines (29 loc) 940 B
function noop() {} let trackTimeoutId: (id: TimeoutType) => void = noop; export type TimeoutType = ReturnType<typeof setTimeout>; function setTimeoutAndTrackId( handler: () => void, timeout?: number, ): TimeoutType { // eslint-disable-next-line no-restricted-globals -- This module is allowed to use setTimeout const timeoutId = setTimeout(handler, timeout); trackTimeoutId(timeoutId); return timeoutId; } function setIntervalAndTrackId( handler: () => void, timeout?: number, ): TimeoutType { // eslint-disable-next-line no-restricted-globals -- This module is allowed to use setInterval const timeoutId = setInterval(handler, timeout); trackTimeoutId(timeoutId); return timeoutId; } export { setTimeoutAndTrackId as setTimeout, setIntervalAndTrackId as setInterval, }; /** For test purposes only */ export function setTimeoutIdTracker(callback: (id: TimeoutType) => void) { trackTimeoutId = callback; }