Skip to main content

Pool <Type>

Index

Constructors

constructor

  • new Pool<Type>(builder: (...args: any[]) => Type, recycler: (instance: Type, ...args: any[]) => Type, maxObjects?: number): Pool<Type>
  • Type parameters

    • Type

    Parameters

    • builder: (...args: any[]) => Type
    • recycler: (instance: Type, ...args: any[]) => Type
    • maxObjects: number = 100

    Returns Pool<Type>

Properties

publicbuilder

builder: (...args: any[]) => Type

Type declaration

    • (...args: any[]): Type
    • Parameters

      • rest...args: any[]

      Returns Type

publicdisableWarnings

disableWarnings: boolean = false

publicindex

index: number = 0

publicmaxObjects

maxObjects: number = 100

publicobjects

objects: Type[] = []

publicrecycler

recycler: (instance: Type, ...args: any[]) => Type

Type declaration

    • (instance: Type, ...args: any[]): Type
    • Parameters

      • instance: Type
      • rest...args: any[]

      Returns Type

publictotalAllocations

totalAllocations: number = 0

Methods

borrow

  • borrow(context: (object: Type) => void): void
  • Use a single instance out of th pool and immediately return it to the pool


    Parameters

    • context: (object: Type) => void

    Returns void

dispose

  • dispose(): void
  • Returns void

done

  • done(...objects: Type[]): Type[]
  • done(): void
  • Signals we are done with the pool objects for now, Reclaims all objects in the pool.

    If a list of pooled objects is passed to done they are un-hooked from the pool and are free to be passed to consumers


    Parameters

    • rest...objects: Type[]

      A list of object to separate from the pool

    Returns Type[]

get

  • get(...args: any[]): Type
  • Retrieve a value from the pool, will allocate a new instance if necessary or recycle from the pool


    Parameters

    • rest...args: any[]

    Returns Type

preallocate

  • preallocate(): void
  • Returns void

using

  • using(context: (pool: Pool<Type>) => void | Type[]): Type[]
  • Use many instances out of the in the context and return all to the pool.

    By returning values out of the context they will be un-hooked from the pool and are free to be passed to consumers


    Parameters

    • context: (pool: Pool<Type>) => void | Type[]

    Returns Type[]