Reputation: 845
I currently have a job that executes some process (it is a bit cpu intensive takes about 10 seconds)
But I would like to cancel it immediately when the next call to executeProcess() comes.
private var myJob: Job? = null
fun executeProcess() {
myJob?.cancel()
myJob = scope.launch(Dispatchers.IO) {
//doCPUIntensiveTask()
//This is always Active!
println("isActive $isActive ")
}
}
How is this possible if I want to reuse the same job object? if not possible, Is there any alternative solution?
Upvotes: 1
Views: 650
Reputation: 2719
Flow
+ flatMapLatest
for same purpose Flow docs, flatMapLatest docsUpvotes: 1