Class: ObjectPool

ObjectPool

ObjectPool

new ObjectPool(size, factory, onGet, onPut) → {ObjectPool}

Creates a preallocated, static pool of objects.
Parameters:
Name Type Description
size Number The number of objects to preallocate.
factory Number A Function that returns a new object.
onGet Function (optional) A Function to call when an instance is retrieved from the pool.
onPut Function (optional) A Function to call when an instance is put back in the pool.
Author:
  • thegoldenmule
Source:
Returns:
Type
ObjectPool

Methods

get() → {Object}

Retrieves an object or null if none are left in the pool.
Source:
Returns:
Type
Object

put(instance)

Puts an object back in the pool.
Parameters:
Name Type Description
instance Object The instance to return to the pool. If the object was not originally retrieved from the pool, nothing will happen...
Source: