FunctionGeneratedTableFactory
The FunctionGeneratedTableFactory's create method is useful for creating tables that are dependent on one or more ticking tables, or for creating tables that need to be refreshed at a regular interval.
The method creates a table by running the user-defined tableGenerator function. This function will be run once when the table is created, and then again when either the sourceTables... tick or when refreshIntervalMs milliseconds have elapsed.
Note
The tableGenerator may access data in the sourceTables, but should not perform any further operations on them without careful handling. Since table operations may be memoized, a table operation may return a table created by a previous invocation of the same operation. Since that result will not have been included in the sourceTables, it is not automatically treated as a dependency for purposes of determining when it is safe to invoke tableGenerator.
This allows race conditions to exist between accessing the operation result and that result's own update processing. It is best to include all dependencies directly in sourceTables or only compute on-demand inputs under a LivenessScope.
When transforming a table, users should generally prefer to use regular table operations instead of this factory because they can perform some operations incrementally. However, create might require less development effort for small tables.
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
| tableGenerator | Supplier<Table> | A function that returns a table to copy into the output table. |
| refreshIntervalMs | int | The interval (in milliseconds) at which the |
| sourceTables | Table... | If the |
Returns
A ticking table (assuming sourceTables have been specified), generated by the tableGenerator function.
Example
In the following example, we create an execution context and a tableGenerator function, which we then use to generate a table that re-runs the tableGenerator function every 2000ms.
If the tableGenerator function depends on one or more ticking tables, the tables must be specified. Adding timeTable1 as a sourceTables... parameter causes the generated table to be recomputed on each tick of the time table.