Comments (5)
Hi @raphaklaus
I'm sorry, but I can't reproduce the bug on my box :S.
BTW if you mean that the spinner disappear AFTER the execution, try to change the true
argument of the stop()
function into false
. That flag enable/disable the line cleaner.
from node-spinner.
Just clarifying things: when loop starts, the spinner does not show up. Only after loop ending, and for a tiny moment (because clear is true
). Changing it to false
the issue persists but after loop ending it appears frozen.
My env (Windows):
$ node -v v4.4.0
$ npm -v 2.7.0
I've tested on Linux and the same situation occurs.
Can I get your box so I can test?
Please, test using this repo: https://github.com/raphaklaus/cli-spinner-issue
Just run npm install
and after node index.js
from node-spinner.
Oh, ok. That is normal. You are locking the V8 vm with the for loop. You have to convert the for loop in something like this:
"use strict";
const Spinner = require('cli-spinner').Spinner;
let downloadSpinner = new Spinner('Downloading.. %s');
downloadSpinner.setSpinnerString('|/-\\');
downloadSpinner.start();
let sum = 0;
let index = 0;
let loop = () => {
setTimeout(() => {
if(index === 9990000) {
downloadSpinner.stop(true);
return;
};
sum = sum * index / sum;
index++;
loop();
}, 0);
};
loop();
If it is ok for you, I close the issue.
from node-spinner.
Why use setTimeout()
?
Hmm, it works, but it's impossible since require modifications inside a processing block which could be in an external module, or in a worst scenario, demand this fix in many third-party modules...
The for
loop locks the setInterval()
inside start()
, is what I've found. Probably it's normal behavior, but must be something less harmful to do...
from node-spinner.
Why use setTimeout()?
V8 is single thread and your for loop occupies that thread for all the time. Using the setTimeout
you give the control back to the vm at every iteration so that it can do 'other things'.
I think you have to refactor your code having in mind how V8 works. (remember that there are async and webworker packages in node too).
from node-spinner.
Related Issues (11)
- NPM source is different than Github source. HOT 1
- Use current position instead of creating newline HOT 2
- Not clear when execute a new console.log HOT 1
- The spinner should disable itself if shell is not interactive HOT 1
- Possible enhancement HOT 2
- Emoji Support! 🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛
- Can't terminate a process
- Animation stops when shelljs.exec or consolo.log is called HOT 3
- No lock file found in the clispinner project on Tag: v0.2.10
- Spinner not appearing until stop called HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-spinner.