jbcarpanelli / spinnies

Node.js module to create and manage multiple spinners in command-line interface programs
MIT License
147 stars 32 forks source link

Bug: Process doesn't exit when `remove` is called on an active spinner #34

Open benjamincburns opened 2 years ago

benjamincburns commented 2 years ago

Expected Behavior

The code below should exit cleanly after the timeout callback is fired.

const Spinnies = require("spinnies");

const spinners = new Spinnies();

spinners.add("spinner-1", { text: "some spinner" });

setTimeout(() => {
  spinners.remove("spinner-1");
  console.log("I should exit now!");
},1000);

Actual Behavior

The spinner is removed as expected, but the node process hangs after printing the text I should exit now.

Workaround

The following code exits as expected (note the addition of spinners.checkIfActiveSpinners() after the call to spinners.remove:

const Spinnies = require("spinnies");

const spinners = new Spinnies();

spinners.add("spinner-1", { text: "some spinner" });

setTimeout(() => {
  spinners.remove("spinner-1");
  spinners.checkIfActiveSpinners();
  console.log("I should exit now!");
},1000);

Potential fix

I think the fix proposed in SweetMNM/dreidels#1 (a PR to a fork of this project) would also work here, though the patch itself likely wouldn't apply cleanly.

benjamincburns commented 2 years ago

Odd that merging my PR to my forked repo closed this ticket... ¯_(ツ)_/¯

rafipiccolo commented 1 year ago

note that if call spinners.succeed("spinner-1"); before or instead of remove it works.