Socket
Socket
Sign inDemoInstall

generic-pool

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generic-pool

Generic resource pooling for Node.JS


Version published
Weekly downloads
3.6M
increased by5.43%
Maintainers
1
Weekly downloads
 
Created

What is generic-pool?

The generic-pool npm package is a resource pooling library that allows users to manage a pool of resources such as database connections, network connections, or any other resource that is expensive to create and can be reused. It helps to limit the number of resources created and manages the allocation and deallocation of these resources efficiently.

What are generic-pool's main functionalities?

Creating a pool of resources

This code sample demonstrates how to create a pool with a maximum of 10 resources and a minimum of 2. The 'create' function is used to create a new resource, and the 'destroy' function is used to clean up a resource when it is no longer needed.

const genericPool = require('generic-pool');
const pool = genericPool.createPool({
  create: () => createMyResource(),
  destroy: (resource) => destroyMyResource(resource)
}, {
  max: 10,
  min: 2
});

Acquiring and releasing resources

This code sample shows how to acquire a resource from the pool and then release it back to the pool once it is no longer needed. The 'acquire' method returns a promise that resolves with a resource when one becomes available.

pool.acquire().then(resource => {
  // use the resource
  pool.release(resource);
}).catch(err => {
  // handle error
});

Draining the pool and shutting down

This code sample illustrates how to drain the pool of all its resources and then shut it down completely. The 'drain' method returns a promise that resolves once all the resources have been returned to the pool and are no longer in use.

pool.drain().then(() => pool.clear());

Other packages similar to generic-pool

Keywords

FAQs

Package last updated on 27 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc