npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-object-pool

v1.1.0

Published

facilitates to create single type of objects and use them on demand

Downloads

5

Readme

#OBJECT POOL

Object Pool will give you the facility to create objects at your will and use them whenever required. You will be able to create objects of your own,store them inside the pool and use them on demand but an object pool can hold only one type of object. You have to pass the object Constructor and parameters to utilize the functionality. An Object Pool can only have single type of objects. You can acquire the objects from the pool and release them back to the pool.You can destroy the objects as well. After a certain timeout the unused objects will get refreshed. There is a parameter named �refeshObject� which will decide whether to recreate these objects or destroy them. You can specify the minimum and maximum number of objects the pool can hold.

Each object pool will have a priority queue which will come in use whenever the number of request for objects exceeds the maximum number of objects and it is not possible to create any more objects for the request. This time the request will be saved in a priority queue based on your requests priority so that whenever an object is released the high priority request is processed first from the queue.

##PoolClient

Used to create an object pool and access

###Methods:

#####createPool(nameOfPool,TypeOfObject,config,min?,max?,timeout?,refreshObject?)

Creates an Object Pool

######Parameters: {string} nameOfPool Name of the Pool being created {function} TypeOfObject Constructor for the objects to be placed in the pool {object} config Parameters for the constructor {number} min? optional. Minimum number of objects the pool can hold. Default : 0 {number} max? optional. Maximum number of objects the pool can hold. Default : 1 {number} timeout? optional. A time limit after which released objects will be automatically freed.
Measured in milliseconds. Default : 30000 {boolean} refreshObject? optional. Specifies whether the idle objects will be recreated/destroyed after timeout Default:true

#####acquireObject(pool,priority,callback?)

This function is used to acquire an object from the pool.

######Parameters: {object} pool Object Pool instance {number} priority This is usually required when the number of requests exceeds maximum number of objects a pool can hold and the pool can not create new object. Then all the requests will be
stored in a priority Queue {function} callback? optional. The function to be called, when the event occurs.

#####releaseObject(pool,object,callback?)

This function is used to release an object to the pool.

######Parameters: {object} pool Object Pool instance {object} object The object that has to be released {function} callback? optional. The function to be called, when the event occurs.

#####freeObject(pool,object,callback?)

This function is used to free an object when not in use.Only released object can be removed from the pool.

######Parameters: {object} pool Object Pool instance {object} object The object that has to be freed. {function} callback? optional. The function to be called, when the event occurs.

#####drainObjects(pool,callback?)

This function in used to drain/free all the released objects when not in use. This function will remove only released objects from the pool.

######Parameters: {object} pool Object Pool instance {function} callback? optional. The function to be called, when the event occurs.

#####getAcquiredOjects(pool)

Get all acquired objects.

######Parameters: {object} pool Object Pool instance

#####getReleasedObjects(pool)

Get all released objects

######Parameters: {object} pool Object Pool instance

#####getNameofPool(pool)

Get the name of the pool

######Parameters: {object} pool Object Pool instance

###Events:

If you are not using any callback function while acquiring,releasing or draining the objects. Then you should add an eventListener to these event types to get back response once you complete the operation.

objectCreated : This event is emitted when you create the minimum number of objects while creating the object pool for the first time

objectAcquired : This event is emitted when you acquire an object

objectReleased : This event is emitted when you release an object

objectFreed : This event is emitted when you free/remove an object

objectDrained : This event is emitted when you free/remove all released objects

objectRefreshed : This event is emitted when idle resources are refreshed( destroyed/recreated )

##PriorityQueue

Queue that will hold requests which is yet to be processed after all the objects of the pool have been acquired.

###Methods:

#####push(data) Push a request to the Priority Queue

######Parameters: {object} data data to be pushed to the queue

#####pop() Pop out a request from the queue

#####getArray()

Get all objects present in the queue