Skip to main content

Pool <Type>

Index

Constructors

constructor

  • new Pool<Type>(builder: () => Type, recycler?: (instance: Type) => Type, maxObjects?: number): Pool<Type>
  • Type parameters

    • Type

    Parameters

    • builder: () => Type
      • optionalrecycler: (instance: Type) => Type
        • maxObjects: number = 100

        Returns Pool<Type>

      Properties

      publicbuilder

      builder: () => Type

      Type declaration

        • (): Type
        • Returns Type

      publicdisableWarnings

      disableWarnings: boolean = false

      publicindex

      index: number = 0

      publicmaxObjects

      maxObjects: number = 100

      publicobjects

      objects: Type[] = []

      publicoptionalrecycler

      recycler?: (instance: Type) => Type

      Type declaration

        • (instance: Type): Type
        • Parameters

          • instance: Type

          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(): Type
        • Retrieve a value from the pool, will allocate a new instance if necessary or recycle from the pool


          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[]