coopernurse / node-pool

Generic resource pooling for node.js
2.38k stars 259 forks source link

fix: unref setTimeout in pool #300

Closed nomagick closed 2 years ago

nomagick commented 2 years ago

I'm using generic-pool in another library. The end developer may not be aware there's a pool running under the hood. Thus unable to drain().then(clear()).

As a library, don't block the process quit. Simply unref all the setTimeouts.

tal952 commented 1 year ago

This throws exception in react:

Uncaught TypeError: setTimeout(...).unref is not a function
nomagick commented 1 year ago

This throws exception in react:

Uncaught TypeError: setTimeout(...).unref is not a function

u running this in browser or node.js or some other javascript runtime?

tal952 commented 1 year ago

In chrome, yes

nomagick commented 1 year ago

This project is node-pool and Generic resource pooling for node.js So I think it's ok to rely on node.js only features.

setTimeout returns a timer in node.js, while in browsers, it returns an integer.

I guess u need to fork and change the code for if you need this library in the browser.

Simply remove the .unref part cuz in browsers u don't need to worry about timer references and quitting the process.

tal952 commented 1 year ago

Actually, in npm, it is called 'generic-pool', and there is no statement that says it's exclusively for Node.js. Is there anything that makes the library Node.js only? Shouldn't we just change the call to .unref?.() and support browsers?

nomagick commented 1 year ago

Actually, in npm, it is called 'generic-pool'

@tal952 I see. I created another PR for this. It's not tested. I just modified the code in my browser.