Class: CalculateOnIdle

PD. CalculateOnIdle


new CalculateOnIdle()

Manages a queue of low-priority calculations to be completed when processing on the main thread is idle.

This class uses the requestIdleCallback() method to process pending calculations.

Author:
  • drajmarsh

Members


:object

calculationCurrent <static>

The current calculation metadata.

Type
  • object

:Array.<object>

calculationsPending <static>

A list of pending calculation metadata.

Type
  • Array.<object>

:boolean

isCalculating <static>

Whether or not one or more calculations are pending or in progress.

Type
  • boolean

Methods


addCalculation(callback, payload [, options]) <static>

Add a calculation to the active calculations queue.

Parameters:
Name Type Argument Description
callback function

A function to invoke in the form callback(payload, fraction).

payload object

An object to use as the first argument to the callback function.

options object <optional>

An optional configuration object.

Properties of options:
Name Type Argument Description
cancelled function <optional>

An optional callback function when cancelled, defaults to null.

complete function <optional>

An optional callback function when complete, defaults to null.


calculate() <static>

The callback method that handles active executing calculations.


cancel() <static>

Call this method to cancel all calculations that are currently in progress.

After this method has been called, all currently active calculations will prematurely terminate and be considered completed.