Giter Club home page Giter Club logo

Comments (5)

helloIAmPau avatar helloIAmPau commented on August 24, 2024

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.

raphaklaus avatar raphaklaus commented on August 24, 2024

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.

helloIAmPau avatar helloIAmPau commented on August 24, 2024

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.

raphaklaus avatar raphaklaus commented on August 24, 2024

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.

helloIAmPau avatar helloIAmPau commented on August 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.