Class: Pool

Pool

A generic class for managing a pool of items.

new Pool (ClassType, initialSize)

Constructs a new Pool.

Name Type Attributes Description
ClassType PoolItemConstructor<T>

The constructor of the items in the pool.

initialSize number <optional>

The initial size of the pool.

Members

totalFree number readonly

Gets the number of items in the pool that are free to use without needing to create more.

totalSize number readonly

Gets the number of items in the pool.

totalUsed number readonly

Gets the number of items in the pool that are currently in use.

Methods

get (data) T

Gets an item from the pool. Calls the item's init method if it exists. If there are no items left in the pool, a new one will be created.

Name Type Attributes Description
data unknown <optional>

Optional data to pass to the item's constructor.

Returns:
Type Description
T The item from the pool.

prepopulate (total) void

Prepopulates the pool with a given number of items.

Name Type Description
total number

The number of items to add to the pool.

return (item) void

Returns an item to the pool. Calls the item's reset method if it exists.

Name Type Description
item T

The item to return to the pool.