Skip to content

Commit 6e5f788

Browse files
committed
fix(cli): Set exit code and shutdown signal for pending async tasks when actions are complete
1 parent 38da035 commit 6e5f788

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

cli/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export async function main() {
2020
} else {
2121
await commandLine(Deno.args)
2222
}
23+
Deno.exit(0)
2324
}
2425

2526
await main()

cli/src/commands/download.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ export async function downloadAction(
5757
// Close after all tasks are queued
5858
worker.postMessage({ command: "done" })
5959

60-
worker.addEventListener("message", (event) => {
61-
if (event.data.command === "closed") {
62-
console.log(
63-
"Download complete. To download all data files, use `datalad get` or `git-annex get`.",
64-
)
60+
await new Promise<void>((resolve) => {
61+
worker.onmessage = (event) => {
62+
if (event.data.command === "closed") {
63+
console.log(
64+
"Download complete. To download all data files, use `datalad get` or `git-annex get`.",
65+
)
66+
resolve()
67+
}
6568
}
6669
})
6770
}

cli/src/commands/upload.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ export async function uploadAction(
153153

154154
// Close after all tasks are queued
155155
worker.postMessage({ command: "done" })
156+
157+
await new Promise<void>((resolve) => {
158+
worker.onmessage = (event) => {
159+
if (event.data.command === "closed") {
160+
resolve()
161+
}
162+
}
163+
})
156164
}
157165

158166
/**

0 commit comments

Comments
 (0)