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
Gets the number of items in the pool that are free to use without needing to create more.
Gets the number of items in the pool.
Gets the number of items in the pool that are currently in use.
Methods
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. |
Prepopulates the pool with a given number of items.
Name | Type | Description |
---|---|---|
total |
number |
The number of items to add to the pool. |
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. |