TaskChain

data class TaskChain(val id: String, val steps: List<TaskRequest>)

Defines a sequential chain of background tasks where each step must succeed before the next one begins. Progress is persisted at every step boundary, so if the app is killed mid-chain (e.g., iOS 30-second limit), execution resumes from the correct step on next launch.

Example

val chain = TaskChain(
id = "user-onboarding",
steps = listOf(
TaskRequest(id = "fetch-profile", type = TaskType.OneTime),
TaskRequest(id = "process-data", type = TaskType.OneTime),
TaskRequest(id = "upload-results", type = TaskType.OneTime,
constraints = Constraints(requiresInternet = true))
)
)
kmpWorker.enqueueChain(chain)
kmpWorker.observeChain("user-onboarding").collect { state -> ... }

Retry within steps

Each step respects its own TaskRequest.retryPolicy. The chain only advances to the next step when a step reaches TaskState.Success. If a step exhausts its retries, the chain enters TaskState.Failed.

Parameters

id

Unique identifier for the chain. Used to observe and cancel the chain.

steps

Ordered list of tasks to execute sequentially.

Constructors

Link copied to clipboard
constructor(id: String, steps: List<TaskRequest>)

Properties

Link copied to clipboard
val id: String
Link copied to clipboard
Link copied to clipboard

Total number of steps in this chain.