TaskChain
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 -> ... }Content copied to clipboard
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.