Constructor
new HybridArrayRunner(returnBehaviorTypeopt, threads)
Create the class and optionaly set the behavior.
See Behaviors for a list of allowed types.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
returnBehaviorType |
string |
<optional> |
Optional parameter to set the return behavior. The default value is SerializedArrayRunner.LAST_RETURN. | |
threads |
number | 5 | Optional parameter to set the number of parallel threads. Defaults to 5. |
- Source:
Extends
Members
(static) ARRAY_RETURN :string
Used to set the behavior to array return. The data from resolved promises for all
will be pushed into an array and returned with the resolved promise.
Type:
- string
- Source:
(static) CONCAT_ARRAY_RETURN :string
Used to set the behavior to concatenated array return. The data from resolved promises for is
expected to be an array. Each array returned is concatenated and returned with the resolved promise.
Type:
- string
- Source:
(static) LAST_RETURN :string
The value used to set the behavior to last return. The data from resolved promises for all
but the last call will be discarded.
Type:
- string
- Source:
behaviorType :string
Getter and setter for the runner return behavior.
Note that the setter will throw an error if the string passed is not one
of the types specified by the static methods. The three types allowed are:
Behaviors:
Behavior Type | Description |
---|---|
HybridArrayRunner.LAST_RETURN | All but the last resolved data is discarded. |
HybridArrayRunner.ARRAY_RETURN | Each resolved data returned is pushed to an array and returned |
HybridArrayRunner.CONCAT_ARRAY_RETURN | The resolved data is an array it's contents are concatenated to the final array for each iteration. |
Type:
- string
- Overrides:
- Source:
numberOfThreads :number
Getter amd setter for the number of parallel threads to use.
Note that the setter will thrown an error if setting the value to
not a number or a number < 1
Type:
- number
- Source:
Methods
run(arrayToIterate, functionToCall, scope, …args) → {Promise}
Slices the given array into an array of buckets of size <= threads.
The contents of each bucket is operated on in parallel.
Once all of the elements of a bucket have been called and resolved,
the next bucket is operated on likewise, until the array is depleted.
Returns a promise when the all iterations are complete.
The data resolved depends on the supplied function return data and the configured
return behavior
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arrayToIterate |
Array | The array who's elements are passed to the function. | |
functionToCall |
function | The function that gets call. It must return a promise. The first parameter is the current array element. | |
scope |
object | The scope for the function to be called in. Necessary if the function is class method. | |
args |
* |
<repeatable> |
Zero or more arguments to send to the function. Note that the first argument here, is the fourth argument to the called function. |
- Overrides:
- Source:
Returns:
A resolved promise is returned if all function calls resolve.
- Type
- Promise