Tower Guidev2
01/06/2023, 11:17 AMactor(start = CoroutineStart.LAZY, context = actorJob, capacity = Channel.UNLIMITED)
) and simply pass a block of code from each of my
modules ViewModels that extend my base ViewModel...Tower Guidev2
01/06/2023, 11:20 AMval reduceChannel: SendChannel<Actionable> = viewModelScope.actor(start = CoroutineStart.LAZY, context = actorJob, capacity = Channel.UNLIMITED) {
for (action in channel) {
when (action) {
is ModuleN_FirstAction -> doActionOne() // Suspending function
is ModuleN_SecondAction -> doActionTwo() // Suspending function
is ModuleN_ThirdAction -> doActionThree() // Suspending function
... // More of the same, different for each module
}
}
}
Tower Guidev2
01/06/2023, 11:24 AMviewModelScope.actor(start = CoroutineStart.LAZY, context = actorJob, capacity = Channel.UNLIMITED) { eachModuleCodeBlock() }
once and i simply pass each modules code block to this base functionTower Guidev2
01/06/2023, 11:28 AMfun frank(reducer: (Actionable) -> Unit) = viewModelScope.actor(start = CoroutineStart.LAZY, context = actorJob, capacity = Channel.UNLIMITED) {
for (action in channel) {
reducer(action)
}
}
however when I call frank as follows:-
frank { action ->
when (action) {
is ModuleN_FirstAction -> doActionOne() // Suspending function
is ModuleN_SecondAction -> doActionTwo() // Suspending function
is ModuleN_ThirdAction -> doActionThree() // Suspending function
... // More of the same, different for each module
}
}
the compliler complains "Suspension functions can only be called within coroutine body
how can I achive the desired result?zokipirlo
01/06/2023, 1:57 PMsuspend
to reducer: fun frank(reducer: suspend (Actionable) -> Unit)