Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 29, 2024 via pnpm

generic-pool 3.9.0

Generic resource pooling for Node.JS
Package summary
Share
0
issues
1
license
1
MIT
Package created
25 Jan 2011
Version published
10 Sep 2022
Maintainers
3
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
generic-pool@3.9.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of generic-pool 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does generic-pool do?

Generic-pool is an npm package delivering a versatile resource pool with a Promise-based API. As developer, it enables you to conveniently reuse or throttle usage of resource-intensive components such as database connections, hence increasing your application's performance and decreasing resource expenses.

How do you use generic-pool?

This npm package is highly intuitive to use. To start with, install the package with the following command:

$ npm install generic-pool [--save]

Afterward, you can utilize the package in your code, using the create and destroy functions in a factory object. Here's an example code snippet on how to use generic-pool:

// import the needed packages
const genericPool = require('generic-pool');
const DbDriver = require('some-db-driver');

// Set the step 1 - Create pool using a factory object
const factory = {
  create: function() {
    return DbDriver.createClient();
  },
  destroy: function(client) {
    client.disconnect();
  }
};

// Define the options
const opts = {
  max: 10, // maximum size of the pool
  min: 2 // minimum size of the pool
};

// Create the pool
const myPool = genericPool.createPool(factory, opts);

// Step 2 - Use pool in your code to obtain/release resources
// Acquire connection - Promise is resolved once a resource becomes accessible
const resourcePromise = myPool.acquire();

resourcePromise
  .then(function(client) {
    client.query("select * from foo", [], function() {
      // return object back to the pool
      myPool.release(client);
    });
  })
  .catch(function(err) {
    // handle error - this is generally a timeout or maxWaitingClients error
  });

// Step 3 - Drain pool during shutdown (optional)
// Only call this once in your application -- at the point you want to shutdown and stop utilizing this pool
myPool.drain().then(function() {
  myPool.clear();
});

Where are the generic-pool docs?

The documentation for the usage of generic-pool is provided in this package's README file on its GitHub page. The documentation includes all methods and functions you can use with generic-pool, as well as various examples and notes on its use. It provides in-depth information about factory object functions (create, destroy, validate), pool configuration options, and pool methods (acquire, release, isBorrowedResource, destroy, on, start, ready, use, and others), which enable developers to adapt generic-pool to their specific needs. Detailed error handling and unit testing instructions are also provided.