Skip to main content
torch.js has not been released yet.
torch.js logotorch.js logotorch.js
PlaygroundContact
Login
Documentation
IntroductionType SafetyTensor ExpressionsTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformancePyTorch CompatibilityBenchmarksDType Coverage
torch.js· 2026
LegalTerms of UsePrivacy Policy
/
/
  1. docs
  2. Spark
  3. spark
  4. SparkExposedFunction

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[]) => unknown

A 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
Previous
SparkDatasetSplit
Next
SparkExposedValue