npkgz / cli-progress

:hourglass: easy to use progress-bar for command-line/terminal applications
https://www.npmjs.com/package/cli-progress
MIT License
1.11k stars 84 forks source link

Fixed MaxListenersExceededWarning when creating many progress bars. #125

Closed TychoTheTaco closed 2 years ago

TychoTheTaco commented 2 years ago

When you create many progress bars (>10), eventually you will get MaxListenersExceededWarning since SIGINT and SIGTERM listeners keep getting added in the constructor but are never removed. I fixed it by adding them on start()/create() and removing them on stop()

AndiDittrich commented 2 years ago

Hi @TychoTheTaco

thanks for your contribution. Indeed that' a possible trap within the current implementation which was not tested - sry. You solution may cause other issues by adding multiple handlers to the event stack, therefore it requires some modification before merging

TychoTheTaco commented 2 years ago

I've added a check to make sure the callback only gets added if the bar is starting for the first time.

AndiDittrich commented 2 years ago

i've applied a slightly modified version of your patch