ahulyk
08/06/2019, 10:16 AMDominaezzz
08/06/2019, 10:22 AMFlow
for this.List<Deferred<T>>.awaitAll()
.val requests = listOf(
async { api.getUser() },
async { api.getComments() }
)
val responses = requests.awaitAll()
louiscad
08/06/2019, 10:29 AMcoroutineScope { … }
and handle errors around it.ahulyk
08/06/2019, 11:53 AMFlow
has great API and I need ConflatedBroadcastChannel
for some reasons. What i did:
flowOf(StreamType.values().asFlow()
.flatMapMerge(10) { stream ->
flowOf(stream to async { apiService.getCurrentInfo(stream.path) })
}
.map { Pair(it.first, it.second.await()) }
.fold(mutableMapOf(), { map: MutableMap<StreamType, ContentMetadataDto>, pair: Pair<StreamType, ContentMetadataDto> ->
map.apply { put(pair.first, pair.second) }
}))
.onEach { map ->
contentMetadata.send(map)
}
.catch {
emit(StreamType.values().map { it to ContentMetadataDto.NO_DATA }.toMap(mutableMapOf()))
}
.collect {
contentMetadata.send(it)
}
Dominaezzz
08/06/2019, 12:02 PMflowOf
with
StreamType.values().associateWith { stream -> async { apiService.getCurrentInfo(stream.path) } }.mapValues { it.second.await() }
(I'm not sure, it's hard to read).flowOf(StreamType.values().asFlow()
.flatMapMerge(10) { stream ->
flowOf(stream to async { apiService.getCurrentInfo(stream.path) })
}
.associate { Pair(it.first, it.second.await()) }))
.onEach { map ->
contentMetadata.send(map)
}
.catch {
emit(StreamType.values().associateWith { ContentMetadataDto.NO_DATA }
}
.collect {
contentMetadata.send(it)
}
ahulyk
08/06/2019, 12:10 PMDico
08/06/2019, 12:53 PMassociateWith