Class: MultiLoader

MultiLoader

Load data from multiple Loader objects, invoking a callback function after all data has been loaded. Call MultiLoader#load to start loading the data.

The DatumLoader class conforms to the Loader interface, so can be used to load arrays of Datum objects based on search criteria.


new MultiLoader(loaders)

Constructor.

Parameters:
Name Type Description
loaders Array.<Loader>

array of loader objects

Version:
  • 1.1.0
Example
const filter1 = new DatumFilter();
filter1.nodeId = 123;
// configure other filter settings here...

const filter2 = new DatumFilter();
filter2.nodeId = 234;
// configure other filter settings here

const urlHelper = new NodeDatumUrlHelper();

new MultiLoader([
  new DatumLoader(urlHelper, filter1),
  new DatumLoader(urlHelper, filter2),
]).load((error, results) => {
  // results is a 2-element array of Datum arrays
});

Members


<static, readonly> version :string

The class version.

Type:
  • string

Methods


callback( [value])

Get or set the callback function, invoked after all data has been loaded. The callback function will be passed two arguments: an error and the results as an array of results from each configured Loader.

Parameters:
Name Type Argument Description
value MultiLoader~dataCallback <optional>

the callback function to use

Returns:

when used as a getter, the current callback function, otherwise this object

Type
MultiLoader~dataCallback | MultiLoader

concurrency( [value])

Get or set the concurrency limit to use for requets.

A default, infinite concurrency queue will be used by default.

Parameters:
Name Type Argument Description
value number <optional>

the concurrency level to use, or Infinity for no limit

Since:
  • 1.1.0
Returns:

when used as a getter, the current concurrency value, otherwise this object

Type
number | MultiLoader

fetch()

Asynchronously load the data.

This method calls MultiLoader#load to perform the actual work.

Returns:

the result promise

Type
Promise.<Array.<Object>>

load( [callback])

Initiate loading the data. This will call Loader#load on each supplied loader, in parallel. As an alternative to configuring the callback function via the MultiLoader#callback method, a callback function can be passed as an argument to this function. This allows this function to be passed to queue.defer, for example.

Parameters:
Name Type Argument Description
callback MultiLoader~dataCallback <optional>

a callback function to use; either this argument must be provided or the function must have already been configured via MultiLoader#callback

Returns:

this object

Type
MultiLoader

Type Definitions


dataCallback( [error], data)

The data callback function.

Parameters:
Name Type Argument Description
error Error <optional>

an error if a failure occurred

data Array.<Object>

the result data from all loaders