1.0.12 • Published 2 years ago

easy-object-pool v1.0.12

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Easy Object Pool

an easy way to use object pool

Install

yarn add easy-object-pool
or
npm i easy-object-pool -S

Usage

import {useObjectPool} from 'easy-object-pool'

class Cat {
}

const [getACat, recycleCat] = useObjectPool<Cat>(() => new Cat())

//create a Cat instance
const cat = getACat()

//recycle a Cat instance
recycleCat(cat)

Api

useObjectPool

function useObjectPool<T>(factoryMethod: (...params: any[]) => T, options?: {
	initializationMethod?: (instance: T, ...params: any[]) => void;
	disposeMethod?: (instance: T, ...params: any[]) => void;
	preInstantiationQuantity?: number;
	limit?: number;
}): [(...params: any[]) => T, (instance: T | T[]) => void, () => void]

Options interface

fieldtyperequireddefaultdescription
factoryMethodsee Declarefactory method to instantiate a instance
initializationMethodsee Declareinitialize a instance when get a instance
disposeMethodsee Declarecall if clean instances
preInstantiationQuantitynumber0instantiate some instances at ahead
limitnumber0set a limit quantity of pool

Returns

[getAInstance, recycleInstance, clear]

fieldtypedescription
getAInstancesee Declareget a instance
recycleInstancesee Declarerecycle a instance or instances
clearsee Declareclean all instances

clearAll

function clearAll()
1.0.11

2 years ago

1.0.12

2 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago