groostav
09/14/2020, 8:59 PMCoroutineDispatcher
into a coroutineContext such that we could ~automagically make progress bars based on the number of suspension points?
I think this is akin to reflecting on the number of states the coroutine state machine has. Of course, while-loops and if-statements blow this up, but still I feel like there might be something here.
Has anybody got an implementation doing something like this?ephemient
09/15/2020, 3:08 AMgildor
09/15/2020, 3:38 AMgroostav
09/15/2020, 6:32 AMfun launchProgressBarableTask(subtaskCount: Int, job: suspend () -> R): Deferred<R> { ... }
suspend fun enterSubtask(subtask: suspend () -> R): R { ... }
usage:
fun onUIEvent(){
launchProgressBarableTask(subtaskCount = customers.size){
for(customer in customers){
results += enterSubtask {
lookupCustomerDetailsFromSlowDB(customer)
}
publish(results)
}
}
}
enterSubtask
since you can infer it from the dispatch but that seems really brittle to megildor
09/15/2020, 7:18 AMfun onUIEvent(){
launchProgressBarableTask(subtaskCount = customers.size){
return mapWithProgress(customers) { customer ->
enterSubtask {
lookupCustomerDetailsFromSlowDB(customer)
}
}
}
}
mapWithProgress
is a method of launchProgressBarableTask
which reports progress for each item of customers
and report it to launchProgressBarableTask