Skip to content

Commit 309b71f

Browse files
committed
better resource management
1 parent dae1304 commit 309b71f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

build/dev.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,19 @@ async function watchDictionary(): Promise<number> {
4545
return status.code;
4646
}
4747
if (import.meta.main) {
48-
if (!await exists(new URL("../dictionary/dictionary.ts", import.meta.url))) {
49-
const Dictionary = await import("../dictionary/build.ts");
50-
await Dictionary.build();
48+
let statusCode: number;
49+
{
50+
await using stack = new AsyncDisposableStack();
51+
if (
52+
!await exists(new URL("../dictionary/dictionary.ts", import.meta.url))
53+
) {
54+
const Dictionary = await import("../dictionary/build.ts");
55+
await Dictionary.build();
56+
}
57+
const statusCodePromise = watchDictionary();
58+
const context = await watchMain();
59+
stack.defer(async () => await context.dispose());
60+
statusCode = await statusCodePromise;
5161
}
52-
const [statusCode, context] = await Promise.all([
53-
watchDictionary(),
54-
watchMain(),
55-
]);
56-
await context.dispose();
5762
Deno.exit(statusCode);
5863
}

0 commit comments

Comments
 (0)