pockethost/frontends/superadmin/src/util/componentCleanup.ts
2023-12-13 23:25:11 -08:00

16 lines
474 B
TypeScript

import { createCleanupManager } from '$shared'
import { onDestroy } from 'svelte'
// TODO: Document this more
// This is used to queue up functions and then destroy them once completed
// Currently being used on the Logging.svelte file to better handle the Real time subscription from Pocketbase.
export const mkCleanup = () => {
const cm = createCleanupManager()
onDestroy(() => cm.shutdown().catch(console.error))
return (cb: () => any) => {
cm.add(cb)
}
}