Skip to content

Commit dae1304

Browse files
committed
better resource management
1 parent 7cd9fc4 commit dae1304

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

build/dev.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ const BUILD_OPTIONS: BuildOptions = {
1212
};
1313
async function watchMain(): Promise<BuildContext<BuildOptions>> {
1414
const buildContext = await context(BUILD_OPTIONS);
15-
await buildContext.watch();
16-
await buildContext.serve({ servedir: "./dist/" });
15+
try {
16+
await buildContext.watch();
17+
await buildContext.serve({ servedir: "./dist/" });
18+
} catch (error) {
19+
await buildContext.dispose();
20+
throw error;
21+
}
1722
return buildContext;
1823
}
1924
async function watchDictionary(): Promise<number> {

dictionary/watch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ async function tryBuild(): Promise<void> {
1313
}
1414
}
1515
if (import.meta.main) {
16-
const watcher = Deno.watchFs("./dictionary/dictionary");
16+
await using stack = new AsyncDisposableStack();
17+
using watcher = Deno.watchFs("./dictionary/dictionary");
1718
let task = Promise.resolve();
19+
stack.defer(async () => await task);
1820
const buildDebounced = debounce(() => {
1921
task = task.then(tryBuild);
2022
}, 200);

0 commit comments

Comments
 (0)