mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.26k stars 2.52k forks source link

Unref Pool #932

Closed skeggse closed 9 years ago

skeggse commented 9 years ago

Add Pool#ref and Pool#unref methods, which allow the program to automatically exit if the pool is inactive (either it has no connections, or the connections are all idle/not acquired).

Nice to have.

dougwilson commented 9 years ago

Why not just call pool.end() when you want to exit your program?

skeggse commented 9 years ago

Because sometimes when I'm writing scripts I just want to unref. You're right, pool.end() is a good way to go when I'm building something I want to deploy. As I said, nice to have.

dougwilson commented 9 years ago

Gotcha. I mainly asked because in my opinion, .ref and .unref are antipatterns in Node.js and I really don't want to add something like that here, especially since it would be a challenge, as implementing something like that on the pool is much harder than it seems if we actually want to keep connections around for re-use (since we'd have to fully unref all the stuff in a connection when it's released and undo that when it's required every time for it to work properly).

skeggse commented 9 years ago

After further thought, I agree: this feature is more trouble than it's worth.