Class Pool<O>

Object pool.

Type Parameters

  • O

Constructors

Methods

Constructors

  • Create a new pool.

    Type Parameters

    • O

    Parameters

    • options: { create: () => O; maxSize?: number; reset?: (o: O) => void }

      Pool creation options

      • create: Function to create a pool entry
      • reset: Optional function that resets an entry when it is returned to the pool
      • maxSize: If this size is exceeded, objects returned to the pool will be discarded

    Returns Pool<O>

Methods

  • Return an object to the pool. If the pool's max size is reached, the object will be discarded.

    Parameters

    • o: O

      Object to return

    Returns void

  • Take an object out of the pool. If the pool is empty, an object will be created.

    Returns O

    Pool object