Skip to content

Weird Behavior of MultiProgressBar #22

@bjesuiter

Description

@bjesuiter

I'm still trying to get my multi-progress-bar to work with this library.

Simplified Working Example

The sleep() calls in there makes sure that my updates will be scheduled slower than the drawing interval.

import { MultiProgressBar } from "https://deno.land/x/progress@v1.3.7/mod.ts";
import { sleep } from "https://deno.land/x/sleep/mod.ts";

const multibar = new MultiProgressBar({
  title: "Multi-Progress Bars",
  complete: "=",
  incomplete: "-",
  interval: 1,
  display: "[:bar] :text :percent :time :completed/:total",
});

multibar.render([
  { text: "progress_1", completed: 1 },
]);

await sleep(0.002);

multibar.render([
  { text: "progress_1", completed: 2 },
  { text: "progress_2", completed: 1 },
]);

await sleep(0.002);

multibar.render([
  { text: "progress_1", completed: 2 },
  { text: "progress_2", completed: 2 },
]);

await sleep(0.002);

multibar.render([
  { text: "progress_1", completed: 3 },
  { text: "progress_2", completed: 2 },
  { text: "progress_3", completed: 1 },
]);

Output

Multi-Progress Bars
[==------------------------------------------------] progress_1 3.00% 0.0s 3/100
[=-------------------------------------------------] progress_2 2.00% 0.0s 2/100
[=-------------------------------------------------] progress_3 1.00% 0.0s 1/100

Problematic Code

Here is a file with 3 mocked progress readables:
https://github.com/codemonument/deno_downstream/blob/main/test/units/multiProgressCliRenderer.test.ts

When I activate the simpleCallbackTarget(), I get a stream of all the state events based on the aforementioned format:

[
  { text: "progress_1", completed: 3 },
  { text: "progress_2", completed: 2 },
  { text: "progress_3", completed: 1 },
]

But when I activate the multiProgressCliRenderer() it only outputs two progress bars at first until they finished and then outputs the third one all at once, like this:

While running:

Multi-Progress Bars
[============================================------] progress_1 87.00% 4.5s 87/100
[============================================------] progress_2 87.00% 4.5s 87/100

When Finished:

Multi-Progress Bars
[==================================================] progress_1 100.00% 5.1s 100/100
[==================================================] progress_2 100.00% 5.1s 100/100
[==================================================] progress_3 100.00% 5.1s 100/100

Test: Adding a sleep

I also tried to add a await sleep(0.002) together with 'interval: 1' in 'multiProgressCliRenderer.ts':
Source File: https://github.com/codemonument/deno_downstream/blob/main/lib/streamAdapters/MultiProgressCliRenderer.ts

return new WritableStream({
    start(_controller) {
      // do init logic, if needed
    },
    async write(state: MultiProgressState, _controller) {
      await sleep(0.002);
      multibar.render(state);
    },
    close() {
    },
    abort(reason) {
      console.error("Stream error:", reason);
    },
  });

But this did not work.

Current State

  1. I think, my sleep is not working correctly here, since it might run in 'parallel' to all the other invocations of 'write' on this writable stream. => So I have to figure something out for that
  2. But I also think that the API for drawing here is inconvenient and that It would be nice to brainstorm with you how to improve at least error reporting, when render requests are dropped by the progress library because of being smaller than the interval.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions