https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

dave08

01/21/2020, 5:18 PM
Does it make sense to add the
flowOn
here:
Copy code
inline fun <reified T : Any, reified R : Any> Flow<T>.concurrentMap(
	dispatcher: CoroutineDispatcher = <http://Dispatchers.IO|Dispatchers.IO>,
	crossinline mapFun: suspend (T) -> R
)Flow<R> = flatMapMerge {
	flow { emit(mapFun(it)) }.flowOn(dispatcher)
}
?
z

Zach Klippenstein (he/him) [MOD]

01/21/2020, 6:52 PM
Looks fine to me
d

dave08

01/21/2020, 8:43 PM
I was thinking that flatMapMerge already uses some dispatcher for concurrency, so that this might be unnecessary?
z

Zach Klippenstein (he/him) [MOD]

01/21/2020, 8:49 PM
All coroutines use a dispatcher, this is useful if you want to map to happen on a different dispatcher (which makes sense, since it’s common for flows to be collected on
Main
or
Default
).
4 Views