ComponentPool<T extends Component> constructor
ComponentPool<T extends Component> ({})
Creates a new component pool with the specified factory, maximum size, and
initial size. The factory is a function that creates new instances of
the component type. The maxSize parameter limits the number of
components that can be stored in the pool, while the initialSize
parameter determines how many components are created initially.
If the initialSize exceeds the maxSize, only maxSize components
will be created and added to the pool.
Implementation
ComponentPool({
required T Function() factory,
this.maxSize = 100,
int initialSize = 0,
}) : _factory = factory {
for (var i = 0; i < initialSize && i < maxSize; i++) {
_available.add(_factory());
}
}