PooledObject

PooledObject

A wrapped object with an updatable state

Constructor

new PooledObject(object, getTimestampopt)

Source:
Example
// Create a pooled object and changes it's state to AVAILABLE
const thingy = new Thingy()
const pooledObject = new PooledObject(thingy)
pooledObject.setToAvailable()
Parameters:
Name Type Default Description
object T

The object being pooled

getTimestampopt function Date.now

Function to get the current timestamp. See Date.now()

Methods

getIdleTime() → {number}

Source:

The number of milliseconds since set to AVAILABLE. Returns -1 if not AVAILABLE

Returns:
Type
number

getLoanPromise() → {Promise.<void>|null}

Source:

Promise that will be resolved when object gets returned. Returns null if not BORROWED

Returns:
Type
Promise.<void> | null

getObject() → {T}

Source:

The object that is pooled

Returns:
Type
T

getState() → {ObjectState}

Source:

Current state of the pooled object

Returns:
Type
ObjectState

setToAvailable() → {this}

Source:

Changes state to AVAILABLE

Returns:
Type
this

setToBorrowed() → {this}

Source:

Changes state to BORROWED and attaches a promise to the pooled object which gets resolved on setToReturned

Returns:
Type
this

setToDestroyed() → {this}

Source:

Changes state to DESTROYED

Returns:
Type
this

setToInvalid() → {this}

Source:

Changes state to INVALID

Returns:
Type
this

setToReturned() → {this}

Source:

Changes state to RETURNED and resolves the loan promise

Returns:
Type
this

setToValidating() → {this}

Source:

Changes state to VALIDATING

Returns:
Type
this

Type Definitions

ObjectState

Source:

The possible states:

  • CREATED
  • AVAILABLE
  • RETURNED
  • VALIDATING
  • BORROWED
  • INVALID
  • DESTROYED
Type:
  • "CREATED" | "AVAILABLE" | "RETURNED" | "VALIDATING" | "BORROWED" | "INVALID" | "DESTROYED"