Git Product home page Git Product logo

Comments (3)

coopernurse avatar coopernurse commented on July 24, 2024

I think this may just be a documentation issue. The intent is that destroy() is an alternative to release(). obj won't be in availableObjects after it is dispensed via acquire, so destroy simply needs to decrement the count and run the destroy() function registered with the pool. For example:

pool.acquire(function(err, client) {
    client.query("select * from foo", [], function() {
        // instead of: pool.release(client);
        // we destroy the client
        pool.destroy(client);
    });
});

Does that make sense? An example use case might be that you want to close the connection to the db after 100 acquires, so you stash a counter on the client obj, incrementing on acquire(). if n < 100 you release(), else you destroy()..

from node-pool.

JoeZ99 avatar JoeZ99 commented on July 24, 2024

ok. now I get it, so if say you detect your conn is corrupted somehow, you need to destroy it and not release it. and yes, it makes sense you only "touch" your connections when you're "inside" the acquire callback. The use case I proposed before implies you can touch the conn once it's been released, and , well, you shouldn't worry about conns in the "available" pool, that is supposed to be a task for the pool manager.

anyway,regarding the use case you said, if you set the pool maximun to 100 you shouldn't get more than 100 conns at anytime. should you?

Do you think a README update is worth it?

from node-pool.

coopernurse avatar coopernurse commented on July 24, 2024

Yep, I'll update the jsdoc comment to clarify the intent of the function.

Re: max pool connections, yes that's right. If you set max to 100, the pool will stop creating objects when 100 is reached, and acquire() calls will block.

This raises an issue though -- currently destroy() doesn't call dispense(). I think it should. I'll open a separate issue for that.

thanks

-- James

from node-pool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.