/*1* cleanup.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*/56import { info } from "../deno_ral/log.ts";78const cleanupHandlers: VoidFunction[] = [];910export function onCleanup(handler: VoidFunction) {11cleanupHandlers.push(handler);12}1314export function exitWithCleanup(code: number) {15// Not using cleanupHandlers.reverse() to not mutate the original array16for (let i = cleanupHandlers.length - 1; i >= 0; i--) {17const handler = cleanupHandlers[i];18try {19handler();20} catch (error) {21info("Error occurred during cleanup: " + error);22}23}24Deno.exit(code);25}262728