Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a generic resource pool. If no resources are available, will create and register a new one. Uses a doubly-linked list as a FIFO queue for unused resources and a Set for in-use resources.

Type parameters

  • T

Hierarchy

  • ResourcePool

Index

Constructors

constructor

  • new ResourcePool(create: function, destroy: function, maxResources: number): ResourcePool
  • Parameters

    • create: function

      Function to be called when a new resource must be created.

        • (): T | PromiseLike<T>
        • Returns T | PromiseLike<T>

    • destroy: function

      Function to be called when a resource must be destroyed.

        • (resource: T): string | PromiseLike<string>
        • Parameters

          • resource: T

          Returns string | PromiseLike<string>

    • maxResources: number

    Returns ResourcePool

    An empty ResourcePool.

Methods

destroyAll

  • destroyAll(): Promise<Array<string>>
  • Returns Promise<Array<string>>

    A Promise that resolves to the response of each call to destroy() after all resources have been returned.

get

  • get(): Promise<T>

numInUse

  • numInUse(): number
  • Resources that are pending are counted here.

    Returns number

    The number of in-use resources owned by this pool.

numOwned

  • numOwned(): number

numUnused

  • numUnused(): number

return

  • return(resource: T): void
  • throws

    Error If the resource does not belong to this pool.

    Parameters

    • resource: T

      The resource to return to the pool.

    Returns void

returnAfter

  • returnAfter<U>(promise: U | PromiseLike<U>, resource: T): Promise<U>
  • Type parameters

    • U

    Parameters

    • promise: U | PromiseLike<U>

      The Promise to settle before returning the resource.

    • resource: T

      The resource to return after promise settles.

    Returns Promise<U>

use

  • use<U>(f: function): Promise<U>
  • Gets a resource, invokes f with it, then returns it to the pool.

    Type parameters

    • U

    Parameters

    • f: function

      A function that accepts a resource and returns some value.

        • (resource: T): U | PromiseLike<U>
        • Parameters

          • resource: T

          Returns U | PromiseLike<U>

    Returns Promise<U>

    A Promise that follows the result of invoking f.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc