Skip to content

@std/cli/unstable-progress-bar pipeTo promise is ignored #6472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nsf opened this issue Mar 10, 2025 · 0 comments
Open

@std/cli/unstable-progress-bar pipeTo promise is ignored #6472

nsf opened this issue Mar 10, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@nsf
Copy link

nsf commented Mar 10, 2025

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:

stream.readable
.pipeTo(writable, { preventClose: this.#options.keepOpen })
.catch(() => clearInterval(this.#id));
is ignored and never awaited. Debugging shows "writer already locked" messages. I believe this is because internally pipeTo does getWriter() and releases the lock on close(), but you need to await for it.

The fix might look like so:

  1. Add #pipePromise: Promise<void>; member to the ProgressBar class.
  2. Store the pipeTo promise:
    this.#pipePromise = stream.readable
      .pipeTo(writable, { preventClose: this.#options.keepOpen })
      .catch(() => clearInterval(this.#id));
    
  3. 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(() => {});
    
@nsf nsf added bug Something isn't working needs triage labels Mar 10, 2025
@kt3k kt3k removed the needs triage label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants