Luis Munoz
07/15/2020, 1:30 AM@Test
fun `experimental`() {
runBlocking {
val scope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)
val songs = listOf("a", "b", "c", "d", "e")
songs.asFlow().flatMapMerge {
requestFlow("${Thread.currentThread().name} $it check")
}
.collect {
println("$it")
}
}
}
fun requestFlow(i: String): Flow<String> = flow {
emit("$i: First")
Thread.sleep(1000)
emit("$i: Second")
}
octylFractal
07/15/2020, 1:31 AMflatMapMerge
for a concurrency level other than 1Luis Munoz
07/15/2020, 1:32 AMsongs.asFlow().flatMapMerge(16) makes no difference it already defaults to 16
public val DEFAULT_CONCURRENCY = systemProp(DEFAULT_CONCURRENCY_PROPERTY_NAME,
16, 1, Int.MAX_VALUE
)
octylFractal
07/15/2020, 1:33 AMscope
thenflatMapMerge
as defaulting to 1Luis Munoz
07/15/2020, 1:34 AMoctylFractal
07/15/2020, 1:34 AMflow { ... }.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
Luis Munoz
07/15/2020, 1:34 AMoctylFractal
07/15/2020, 1:34 AMLuis Munoz
07/15/2020, 1:35 AMjulian
07/15/2020, 1:58 AMLuis Munoz
07/15/2020, 1:59 AM@Test
fun `experimental`() {
runBlocking {
val songs = listOf("a", "b", "c", "d", "e")
songs.asFlow().flatMapMerge(16) {
requestFlow(" $it check").flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
}.collect {
println("$it")
}
}
}
fun requestFlow(i: String): Flow<String> = flow {
emit("${Thread.currentThread().name} $i: First")
Thread.sleep(1000)
emit("${Thread.currentThread().name} $i: Second")
}
julian
07/15/2020, 2:02 AMZach Klippenstein (he/him) [MOD]
07/15/2020, 3:42 PMsleep
instead of delay
? Unless you're actually trying to simulate IO that is almost always wrong.Luis Munoz
07/21/2020, 1:00 AM