Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/core/cleanup.ts
3557 views
1
/*
2
* cleanup.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { info } from "../deno_ral/log.ts";
8
9
const cleanupHandlers: VoidFunction[] = [];
10
11
export function onCleanup(handler: VoidFunction) {
12
cleanupHandlers.push(handler);
13
}
14
15
export function exitWithCleanup(code: number) {
16
// Not using cleanupHandlers.reverse() to not mutate the original array
17
for (let i = cleanupHandlers.length - 1; i >= 0; i--) {
18
const handler = cleanupHandlers[i];
19
try {
20
handler();
21
} catch (error) {
22
info("Error occurred during cleanup: " + error);
23
}
24
}
25
Deno.exit(code);
26
}
27
28