Utils

A set of utilities

Description:
  • A set of utilities

Source:

Methods

(static) sum(array) → {Number}

Description:
  • Sum the values of the array (must be numbers).

Source:
Parameters:
Name Type Description
array Array

array of number values

Returns:

the sum of the values in the array

Type
Number

(static) tryUntil(generationFunc, testFunc) → {*}

Description:
  • The idiomatic way of trying something repeatedly until the outcome is acceptable can be awkard to express (do/while loop), so this converts it into something that is easier to read and understand. There is a counter to break out of accidental infinite loops.

Source:
Parameters:
Name Type Description
generationFunc function

a function that returns a value

testFunc function

that returns true if result is acceptable, false otherwise

Returns:

the final result

Type
*

(static) yieldToEventLoop() → {Promise.<void>}

Description:
  • Yields control back to the event loop as a macrotask (not just a microtask), so that anything else already queued to run — e.g. a Comlink call waiting on the same worker's message queue — gets a chance to execute before the caller resumes. Works identically in a browser Worker and a Node worker_threads Worker, since both implement setTimeout.

Source:
Returns:
Type
Promise.<void>