FitHandle

interface FitHandle(source)

Live reference to a fitting job submitted through a DistributionModelingSession, parallel to ksl.app.session.RunHandle.

The job runs asynchronously on a background coroutine; observe events for lifecycle progress and await result for the terminal outcome. result.await() never throws — it resolves to a FitResult variant for every outcome including cancellation and failure.

Properties

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

Hot SharedFlow of lifecycle events. Replays a bounded recent history, so a subscriber that attaches shortly after submit returns can initialise its UI without missing the start event on very fast fits. The flow is never closed; it simply stops emitting after the terminal event (FitCompleted, FitFailed, or FitCancelled).

Link copied to clipboard
abstract val fitId: String

Unique identifier for this fit, assigned by the session.

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

Deferred terminal result. Resolves normally with one of FitResult.Completed, FitResult.Failed, or FitResult.Cancelled.

Functions

Link copied to clipboard

Synchronously waits for result and returns it via runBlocking. Do not call from inside a coroutine running on the session's own scope, or from a UI thread — those callers should observe result asynchronously instead.

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

Requests cooperative cancellation. The public lifecycle resolves immediately with a Cancelled result and FitCancelled event as soon as this handle wins the terminal state; the worker is then cancelled. Calling cancel more than once or after the fit has already ended is safe and has no effect.