UNPKG

@smikhalevski/object-pool

Version:
36 lines (35 loc) 1.3 kB
/** * The array-backed object pool implementation. * * @see https://en.wikipedia.org/wiki/Object_pool_pattern Object pool pattern */ export declare class ObjectPool<T> { private _cache; private _cursor; private _factory; private _reset; /** * Creates the new {@link ObjectPool} instance. * * @param factory The factory that produces new values. * @param reset The callback that is invoked when value is returned to the pool via {@link release}. */ constructor(factory: () => T, reset?: (value: T) => void); /** * Returns the next value from the pool. If there's no value available then the factory is called to produce a new * value which is added to the pool. */ take(): T; /** * Returns a value to the pool so it can be retrieved using {@link ObjectPool.take}. There's no check that value was * already returned to the pool and no check that value was in the pool previously. So ensure you don't release the * same value twice or release a value that doesn't belong to the pool. */ release(value: T): void; /** * Populates pool with new values produced by the factory. * * @param count The integer number of values to produce. */ allocate(count: number): void; }