RunHandle

interface RunHandle(source)

Live reference to a simulation run submitted via Runner.submit.

A RunHandle is returned immediately by Runner.submit; the simulation executes asynchronously on a background thread. Callers observe progress by collecting events and obtain the terminal outcome by awaiting result.

val handle = runner.submit(RunRequest.SingleRun(model))

// Collect lifecycle events (usually in a dedicated coroutine):
launch { handle.events.collect { event -> updateUi(event) } }

// Await the terminal result:
when (val r = handle.result.await()) {
is RunResult.Completed -> showResults(r.summary)
is RunResult.Cancelled -> showCancelled(r.reason)
is RunResult.Failed -> showError(r.error)
}

Properties

Link copied to clipboard
abstract val events: SharedFlow<RunEvent>

Hot SharedFlow of lifecycle events emitted during the run.

Link copied to clipboard
abstract val result: Deferred<RunResult>

Deferred terminal result of the run.

Link copied to clipboard
abstract val runId: String

Unique identifier for this run, assigned by Runner.

Functions

Link copied to clipboard

Synchronously waits for result and returns it.

Link copied to clipboard
abstract fun cancel(reason: String = "Cancelled by user")

Requests cooperative cancellation of the run.

Link copied to clipboard
open fun cancelScenario(scenarioName: String): Boolean

Cancel a single scenario by name without stopping the enclosing run. Only meaningful for scenario sweeps — other orchestrators return false from the default implementation.