Class: ResourceSelector

ResourceSelector(strategy, eqComparer)

Given any number of resources, this class helps to select an appropriate resource by a pre-defined strategy, such as least-recently used.

Constructor

new ResourceSelector(strategy, eqComparer)

Parameters:
Name Type Description
strategy ResourceSelectionStrategy | Number
eqComparer EqualityComparer.<T>
Author:
Source:

Extends

Members

hasResources :Boolean

Type:
  • Boolean
Source:

strategy :ResourceSelectionStrategy|Number

Type:
Source:

strategy

Source:

Methods

addResource(resource) → {this}

Parameters:
Name Type Description
resource T A resource
Source:
Throws:
If the resource was added previously.
Type
Error
Returns:
Type
this

hasResource(resource) → {Boolean}

Note that this method compares the actual resource (@see {T}), not its wrapper @see {Resource}.
Parameters:
Name Type Description
resource T
Source:
Returns:
Type
Boolean

removeResource(resource) → {this}

Remove a previously added resource from this selector.
Parameters:
Name Type Description
resource T The resource to remove.
Source:
Returns:
Type
this

select() → {Resource.<T>}

The main method to select the next resource. You must not rely on the expected order if all resources are yet unused
Source:
Returns:
The next resource, according to the currently selected strategy. It can be used by calling @see {Resource.use()}.
Type
Resource.<T>