JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q46622F
  • License MIT

Package Exports

  • easy-object-pool
  • easy-object-pool/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (easy-object-pool) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

field type required default description
factoryMethod see Declare factory method to instantiate a instance
initializationMethod see Declare initialize a instance when get a instance
disposeMethod see Declare call if clean instances
preInstantiationQuantity number 0 instantiate some instances at ahead
limit number 0 set a limit quantity of pool

Returns

[getAInstance, recycleInstance, clear]

field type description
getAInstance see Declare get a instance
recycleInstance see Declare recycle a instance or instances
clear see Declare clean all instances

clearAll

function clearAll()