AmrJyniat
07/28/2022, 9:07 AMFlow
each x seconds? like:
val flow = flow {
emit(doApiCall())
}
.onEach{ delay(1000) }// something like that
........
flow.collect{
//get flow value
}
I searched a lot but it seems that I need to put the code in fun and call it each time, what do you think?ephemient
07/28/2022, 9:17 AMflow {
while (true) {
emit(doApiCall())
delay(1000)
}
}
AmrJyniat
07/28/2022, 9:37 AMephemient
07/28/2022, 10:16 AMfun <T> Flow<T>.repeatWhen(suspend predicate: suspend FlowCollector<T>.() -> Boolean): Flow<T> = flow {
do {
yieldAll(this@repeatWhen)
} while (predicate())
}
::doApiCall.asFlow()
.repeatWhen {
delay(1000)
true
}
AmrJyniat
07/28/2022, 11:06 AMyieldAll()
fun in this scope, Although I tested yield()
but didn't workedephemient
07/28/2022, 11:27 AMemitAll
AmrJyniat
07/28/2022, 11:33 AMDALDEI
08/07/2022, 3:13 PMephemient
08/07/2022, 4:44 PMchannelFlow
involves more overhead than `kotlinx.coroutines.flow.internal.flowScope`/`.scopedFlow`