@tsdotnet/object-pool - v2.0.0
    Preparing search index...

    Class default<T>

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

    Type Parameters

    • T

    Hierarchy

    • default
      • default
    Index

    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.

      • Optional_recycler: (o: T) => void

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

      • _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 number

    • get maxSize(): number

      The soft ceiling by which the pool is trimmed.

      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

    • 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

      Returns void

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

      Parameters

      • Optionalfactory: () => T

      Returns T

    • Empties the pool into an array and returns it.

      Returns T[]

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

      Parameters

      • Optionalmax: number

      Returns void

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

      Returns undefined | T

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

      Type Parameters

      • T

      Parameters

      • Optionalgenerator: (...args: any[]) => T
      • Optionalrecycler: (o: T) => void
      • max: number = DEFAULT_MAX_SIZE

      Returns default<T>

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

      Type Parameters

      Parameters

      • Optionalgenerator: (...args: any[]) => T
      • max: number = DEFAULT_MAX_SIZE

      Returns default<T>