Skip to content
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

Is it possible to run ora on Worker? #218

Open
jon9090 opened this issue Nov 24, 2022 · 1 comment
Open

Is it possible to run ora on Worker? #218

jon9090 opened this issue Nov 24, 2022 · 1 comment

Comments

@jon9090
Copy link

jon9090 commented Nov 24, 2022

Is it possible to run ora on Worker?

Currently, it freezed:

Open this stackblitz example code
Then in the stackblitz terminal run node index.js.

Now you can see that working is work as expected (because it's on the main thread), but loading is not because it on the worker thread.

index.js:

// run `node index.js` in the terminal
const { Worker } = require('node:worker_threads');
const path = require('path');
const ora = require('ora');

console.log(`Hello Node.js v${process.versions.node}!`);

new Worker(path.resolve(__dirname, './worker.js'));

ora('working...').start();

setTimeout(() => {}, 10 * 1000); //<-- prevent node to exit.

worker.js:

const ora = require('ora');

ora('loading...').start();
@hhk-png
Copy link

hhk-png commented Jul 9, 2023

If the environment is not interactive, it will output the - ${this.text}\n in the terminal and not work normally. There is a section of code in the source that expresses this meaning.

if (!this.#isEnabled) {
	if (this.text) {
		this.#stream.write(`- ${this.text}\n`);
	}
	return this;
}

and #isEnabled property is equal to

this.#isEnabled = typeof this.#options.isEnabled === 'boolean' ? this.#options.isEnabled : **isInteractive**({stream: this.#stream})

The Worker environment is not interactive. The isInteractive() will return false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants