poolz

A simple javascript object pool, built for Node.js

npm install poolz
2 downloads in the last week
8 downloads in the last month

Poolz

A simple javascript object pool, built for Node.js

How to use

Installation:

npm install poolz

That's it! You're ready to go!

Usage:

  1. var poolz = require("poolz") returns the poolz object.
  2. poolz.pool(options) creates a new pool and returns it.

options is an object containing:

  • min: either an integer, representing the minimum objects in the pool. This requires create. Or false, which means 'no minimum'.
  • max: always an integer. false is not supported.
  • create: (optional) Function which returns a new object for the pool. Called when there aren't enough objects. Required when min is set to an integer.

Pool Object

.add(object)

  • Function
  • Parameters:
    • object: object to be added to the pool.
  • Returns an error when maximum has been reached.

.get()

  • Function
  • Parameters: none
  • Returns the first free object it can find

.release(object)

  • Function
  • Parameters:
    • object: object to be released.
  • When an object has been get(), it has to be realeased to be used again.
  • Returns an error if the object was not found.

.remove(object)

  • Parameters:
    • object: object to be removed from pool
  • Returns an error if the object was not found.

.create()

  • Function (optional)
  • Parameters: none
  • Creates a new object when the pool is low on objects
  • Poolz sets this function on initialization
  • See Usage for more info

.min

  • Integer / false
    • Integer: Sets the minimum amount of objects that have to be present in the pool
    • false: No minimum
  • Poolz sets this value on initialization
  • It is best not to touch this value (but it shouldn't be a problem if you do)

.max

  • Integer
  • Sets the maximum amount of objects in the pool
  • Set it to a high number if you don't want a maximum
  • Poolz sets this value on initialization
  • It is best not to touch this value (but it shouldn't be a problem if you do)

.free

  • Array
  • Contains all the free objects
  • It is best not to touch this

.busy

  • Array
  • Contains all the busy objects
  • It is best not to touch this

Notes

  • A Note On Errors:

    • When something goes wrong, Poolz returns an error object. This is simply an object containing: {"err": "some error message"}.
  • External Links:

    • Github, where the code is hosted.
    • NPM, where the module is available for download.
    • My Personal Site, which uses Poolz on the server.

LICENSE

The MIT License (MIT)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you