A flexible Object Pool that trims the pool down to the specified max size after a specified delay.

Type Parameters

  • T

Hierarchy

  • default
    • default

Constructors

  • A transient amount of object to exist over _maxSize until trim() is called. But any added objects over _localAbsMaxSize will be disposed immediately.

    Type Parameters

    • T

    Parameters

    • Optional _generator: ((...args: any[]) => T)

      The delegate to create new items.

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

          • Rest ...args: any[]

          Returns T

    • Optional _recycler: ((o: T) => void)

      An optional delegate to clean/process items before returning to the pool.

        • (o: T): void
        • Parameters

          • o: T

          Returns void

    • _maxSize: number = DEFAULT_MAX_SIZE

      The soft ceiling by which the pool is trimmed. Default is 1000.

    Returns default<T>

Accessors

  • get count(): number
  • Current number of objects in the pool.

    Returns

    Returns number

  • get maxSize(): number
  • The soft ceiling by which the pool is trimmed.

    Returns

    Returns number

Methods

  • Returns void

  • Signals the pool to trim after a delay.

    Parameters

    • msLater: number = AUTO_REDUCE_DEFAULT_MS
    • max: number = NaN

    Returns void

  • Shortcut for toArrayAndClear();

    Returns T[]

  • Gives an item to the pool. If recyclable, will be added to the recycler.

    Parameters

    • entry: T

    Returns void

  • Short term renting of an item.

    Parameters

    • closure: ((entry: T) => void)
        • (entry: T): void
        • Parameters

          • entry: T

          Returns void

    Returns void

  • Returns an item from the pool or creates one using the provided factory or the default factory configured with the pool.

    Returns

    Parameters

    • Optional factory: (() => T)
        • (): T
        • Returns T

    Returns T

  • Empties the pool into an array and returns it.

    Returns

    Returns T[]

  • Trims the pool to the optional specified max (or the default).

    Parameters

    • Optional max: number

    Returns void

  • Attempts to get an item from the pool. Returns undefined if none available.

    Returns

    Returns undefined | T

  • Creates a pool using the specified generator and optional recycler.

    Returns

    Type Parameters

    • T

    Parameters

    • Optional generator: ((...args: any[]) => T)
        • (...args: any[]): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    • Optional recycler: ((o: T) => void)
        • (o: T): void
        • Parameters

          • o: T

          Returns void

    • max: number = DEFAULT_MAX_SIZE

    Returns default<T>

  • Creates an auto-recycled pool using the specified generator.

    Returns

    Type Parameters

    Parameters

    • Optional generator: ((...args: any[]) => T)
        • (...args: any[]): T
        • Parameters

          • Rest ...args: any[]

          Returns T

    • max: number = DEFAULT_MAX_SIZE

    Returns default<T>

Generated using TypeDoc