spark.SparkController
export interface SparkController {
/**
* Current execution status.
*
* @readonly
*/
readonly status: SparkStatus;
/**
* Pause execution at the next checkpoint.
*
* The worker will pause when `checkpoint()` is next called,
* and remain paused until `resume()` is called.
*/
pause(): void;
/**
* Resume paused execution.
*
* If not paused, this is a no-op.
*/
resume(): void;
/**
* Stop execution.
*
* The next `checkpoint()` will throw `SparkStopError`.
* The worker will terminate after the error is thrown.
*/
stop(): void;
/**
* Cooperative yield point for pause/resume/stop and hot reload.
*
* Call this at regular intervals in your training loop.
* It will:
* - Throw `SparkStopError` if stopped
* - Throw `SparkReloadError` if hot reload is pending
* - Block until resumed if paused
* - Yield control to allow UI updates
*
* @throws {SparkStopError} If execution was stopped
* @throws {SparkReloadError} If hot reload is pending
*/
checkpoint(): Promise<void>;
}- readonly
status(SparkStatus) - – Current execution status.
pause(() => void)- – Pause execution at the next checkpoint. The worker will pause when
checkpoint()is next called, and remain paused untilresume()is called. resume(() => void)- – Resume paused execution. If not paused, this is a no-op.
stop(() => void)- – Stop execution. The next
checkpoint()will throwSparkStopError. The worker will terminate after the error is thrown. checkpoint(() => Promise<void>)- – Cooperative yield point for pause/resume/stop and hot reload. Call this at regular intervals in your training loop. It will: - Throw
SparkStopErrorif stopped - ThrowSparkReloadErrorif hot reload is pending - Block until resumed if paused - Yield control to allow UI updates
Controller for managing execution in the worker.
Provides cooperative pause/resume/stop and checkpoints for hot reload.
Call checkpoint() at regular intervals in your training loop.
Examples
const ctrl = spark.controller();
async function train() {
for (const batch of data) {
await ctrl.checkpoint(); // Allow pause/stop/reload here
// ... training step
}
}