TaskChainExecutor
class TaskChainExecutor(worker: KmpWorker, chainRepository: ChainRepository, scope: CoroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob()))
Drives the execution of a TaskChain by observing TaskMonitor and advancing the chain one step at a time.
Step-level state restoration
Every time a step completes successfully, ChainRepository.updateStep is called before the next step is enqueued. If the app is killed mid-chain and relaunched, call restorePendingChains to resume from the last committed step.
Usage
val executor = TaskChainExecutor(kmpWorker, chainRepository, appScope)
executor.execute(myChain)
// On app startup (after TaskMonitor.replayPendingEvents()):
executor.restorePendingChains()Content copied to clipboard
Constructors
Link copied to clipboard
constructor(worker: KmpWorker, chainRepository: ChainRepository, scope: CoroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob()))
Functions
Link copied to clipboard
Cancels a running chain and removes its progress record. Any currently-executing step is cancelled via KmpWorker.cancel.
Link copied to clipboard
Starts executing chain from step 0. Registers an internal observer that advances steps on success.
Link copied to clipboard
Restores all chains that were RUNNING when the app was last terminated. Call at app startup, after TaskMonitor.replayPendingEvents.