Open
Description
The following code:
import { ProgressBar } from "@std/cli/unstable-progress-bar";
const pb1 = new ProgressBar(Deno.stdout.writable, { max: 5 });
pb1.add(5);
await pb1.end();
const pb2 = new ProgressBar(Deno.stdout.writable, { max: 5 });
pb2.add(5);
await pb2.end();
fails with:
[00:00] [##################################################] [0.00/0.00 KiB]
error: Top-level await promise never resolved
await pb2.end();
^
at <anonymous> (file:///home/nsf/tmp/denotest/main.ts:8:1)
I think this is because returned pipeTo promise here:
std/cli/unstable_progress_bar.ts
Lines 187 to 189 in 14b96c6
The fix might look like so:
- Add
#pipePromise: Promise<void>;
member to theProgressBar
class. - Store the pipeTo promise:
this.#pipePromise = stream.readable .pipeTo(writable, { preventClose: this.#options.keepOpen }) .catch(() => clearInterval(this.#id));
- Await for it in
end()
:await this.#print() .then(() => this.#writer.write(this.#options.clear ? "\r\u001b[K" : "\n")) .then(() => this.#writer.close()) .then(() => this.#pipePromise) .catch(() => {});