S.
05/06/2025, 12:45 PMCLOVIS
05/06/2025, 2:05 PMsuspend () -> Flow<T>
is always a code smell, it's code that suspends in two different waysCLOVIS
05/06/2025, 2:05 PMfun foo(): Flow<T> = flow {
// initialize your stuff
emitAll(/* your request */)
}
S.
05/06/2025, 2:10 PMCLOVIS
05/06/2025, 2:10 PMflow {}
you can suspend, so it's not a problem.S.
05/06/2025, 2:11 PMCLOVIS
05/06/2025, 2:13 PMFlow<T>
means "a suspending function that returns multiple values", so suspend () -> Flow<T>
is "a suspending function which returns a suspending function which returns multiple values", which is repetitive and confusing, because you don't know what happens at each of the suspensionsCLOVIS
05/06/2025, 2:13 PMsuspend
function shouldn't have a CoroutineScope
receiverS.
05/06/2025, 2:16 PMCLOVIS
05/06/2025, 2:17 PMCLOVIS
05/06/2025, 2:18 PMfun <T> realFlow(block: suspend () -> Flow<T>) = flow {
emitAll(block())
}
to adapt between your old functions and the well-written onesAlexander Sysoev
05/08/2025, 1:21 PM