Skip to content

Bar not appearing #195

@cobbdb

Description

@cobbdb

I'm trying to use this library inside of threads, but for some reason I don't see any bars being drawn. It seems to work fine without threads though so I'm hoping someone knows what's going on here?

const ProgressBar = require('progress');
const {
  Worker,
  isMainThread,
  parentPort,
  workerData,
} = require('worker_threads');
const files = {
  'eta.js': 187,
  'generic-bar.js': 589,
  'multi-bar.js': 5342,
  'options.js': 42,
  'single-bar.js': 2123,
  'terminal.js': 4123,
};

if (isMainThread) {
  const entries = Object.entries(files);
  for (const file of entries) {
    const worker = new Worker(__filename, { workerData: file });
    worker.on('message', (data) => {
      console.log('... OK', data);
    });
    worker.on('error', (err) => {
      console.log('[ERR]', err);
    });
    worker.on('exit', (code) => {
      if (code !== 0) {
        console.log(`Worker stopped with exit code ${code}`);
      }
    });
  }
} else {
  console.log('... making new bar', workerData);
  const bar = new ProgressBar(':bar', {
    total: workerData[1],
  });

  const timer = setInterval(() => {
    bar.tick();
    if (bar.complete) {
      clearInterval(timer);
    }
  }, 3);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions