spark.SparkExposedFunction
export interface SparkExposedFunction<T extends (...args: unknown[]) => unknown> {
/**
* Call the function in the worker.
*
* Arguments are serialized and sent to the worker, where the function
* is executed. The result is serialized and returned.
*
* @param args - Arguments to pass to the function
* @returns Promise that resolves with the function result
*/
(...args: Parameters<T>): Promise<ReturnType<T>>;
}Textends (...args: unknown[]) => unknownA function exposed from the worker to the UI.
When called from the UI, the function executes in the worker and the result is returned via Promise.
Examples
// Worker:
async function train() { ... }
spark.expose({ train });
// UI:
const s = spark.use(torch);
await s.train(); // Executes in worker, returns Promise