benkuly
01/17/2022, 1:31 PMflow.flatMapLatest { flowValue ->
stateFlowDependingOnFlowValue(flow1Value,scope) // internally does something like `.stateIn(scope)`
}
Given this code, every time flatMapLatest is called, a new coroutine is spawned in the scope. Is there a way to use a scope, which is only active within flatMapLatest, so old calculations would be cancelled?bezrukov
01/17/2022, 1:36 PMflow.transformLatest { flowValue ->
coroutineScope {
emitAll(stateFlowDependingOnFLowValue(flowValue, this))
}
}benkuly
01/17/2022, 1:39 PMcoroutineScope prevent transformLatest to complete, because of stateIn ?bezrukov
01/17/2022, 1:46 PMbezrukov
01/17/2022, 1:47 PMflow {} + coroutineScope { } :
flow.flatMapLatest { flowValue ->
flow {
coroutineScope {
emitAll(stateFlowDependingOnFlowValue(flow1Value,scope))
}
}
}benkuly
01/17/2022, 2:34 PMtransformLatest seems to be perfect :)