bevry-archive / bal-util

Utility functions for JavaScript and Node.js used and maintained by Benjamin Lupton

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Globals

jameswyse opened this issue · comments

Hello! I recently started using watchr which depends on this package and discovered that it leaks 6 global variables. Just wondering what your reason was as It's common practice to avoid globals wherever possible. Not a huge deal given their names but I like to keep things clean! 👍

warn: Global Defined: numberOfOpenFiles
warn: Global Defined: maxNumberOfOpenFiles
warn: Global Defined: waitingToOpenFileDelay
warn: Global Defined: numberOfOpenProcesses
warn: Global Defined: maxNumberOfOpenProcesses
warn: Global Defined: waitingToOpenProcessDelay

Cheers!

With node programs you're only allowed a max amount of open processes and open files at once. This is not automatically handled by node. So we utilise these global variables to keep track of how many things we have open, so if we have our limit open, then it will wait until some things close down before opening more.

Needs to be global, as if it were local then each bal-util instance would all have their own counters - which naturally would go over the global limit. Nothing we can do about this :(

I'm guessing mocha was what yelled at you? If you got a while, we use joe for our testing as we found mocha to be a pain.

Cheers, does that clear things up for you? Feel free to post back if you'd like more info :)

Thanks, that clears things up. I had a glance over the code and thought that was the case. Yeah I noticed it with mocha, joe looks like a great alternative! Cheers!