TaskState

sealed class TaskState

Represents the current lifecycle state of a background task.

State machine:

[Scheduled] → [Running] → [Success]
↘ [Failed]
↘ [TimedOut] (task exceeded KmpWorkerConfig.taskTimeout)
[Scheduled] → [Cancelled] (before execution begins)

Inheritors

Types

Link copied to clipboard
data class Cancelled(val reason: String = "") : TaskState

Task was explicitly cancelled via KmpWorker.cancel. No retry will occur after cancellation.

Link copied to clipboard
data class Failed(val throwable: Throwable, val retryCount: Int = 0, val willRetry: Boolean = false) : TaskState

Task failed with an exception.

Link copied to clipboard
data class Running(val progress: Float? = null, val message: String? = null) : TaskState

Task handler is currently executing.

Link copied to clipboard
data object Scheduled : TaskState

Task has been accepted and queued for execution.

Link copied to clipboard
data object Success : TaskState

Task completed successfully.

Link copied to clipboard
data class TimedOut(val afterMillis: Long) : TaskState

Task exceeded the KmpWorkerConfig.taskTimeout duration and was stopped. No retry will occur after a timeout — treat the same as Cancelled.

Properties

Link copied to clipboard

True if the task is currently active (Scheduled or Running).

Link copied to clipboard

True if the task is in a terminal state (Success, Failed without retry, Cancelled, or TimedOut).