Garbage collect segments.

This commit is contained in:
Dermot Duffy
2022-09-24 13:39:17 -07:00
parent a2e80d93a3
commit 5ec3cbac54
5 changed files with 79 additions and 8 deletions
+16
View File
@@ -94,4 +94,20 @@ export const isHoverableDevice = (): boolean => window.matchMedia(
*/
export const formatDateAndTime = (date: Date): string => {
return format(date, 'yyyy-MM-dd HH:mm');
}
/**
* Run a function in idle periods. If idle callbacks are not supported (e.g.
* Safari) the callback is run immediately.
* @param func The function to call.
* @param timeout The maximum number of seconds to wait.
*/
export const runWhenIdleIfSupported = (func: () => void, timeout?: number): void => {
if (window.requestIdleCallback) {
window.requestIdleCallback(func, {
...(timeout && { timeout: timeout})
});
} else {
func();
}
}