Kulwinder Singh
12/21/2018, 9:22 AMvideosList.forEachIndexed { index, video: BaseVideo ->
val userData = getUserData(video)*//calling suspend function*
listWithData[index].userData = userData
}
gildor
12/21/2018, 9:29 AMval result: List<UserData> = videosList.map { video ->
async { getUserData(video) }
}.awaitAll()
Kulwinder Singh
12/21/2018, 9:37 AM"But in this case you do not limit concurrency" h
gildor
12/21/2018, 9:37 AMKulwinder Singh
12/21/2018, 9:38 AMKulwinder Singh
12/21/2018, 9:39 AMgildor
12/21/2018, 9:40 AMKulwinder Singh
12/21/2018, 9:41 AMgildor
12/21/2018, 9:44 AMval result: List<UserData> = videosList.chunked(PARALLEL_COROUTINES_AMOUNT).flatMap { videos ->
videos.map { video ->
async { getUserData(video) }
}.awaitAll()
}
Kulwinder Singh
12/21/2018, 9:57 AMvideosList
is having , it has only 5 items ,so i don't think i have to convert it to chucked
. i'm paginating RecyclerView
loading data 5 items each timegildor
12/21/2018, 10:02 AMKulwinder Singh
12/21/2018, 10:11 AMasync
coroutines
created ,so how much it will effect ?gildor
12/21/2018, 10:37 AMKulwinder Singh
12/21/2018, 10:51 AMprivate suspend fun getUserData(video: BaseVideo): UserDataAboutVideo? {
return if (currentUser != null) {
val userDataDocument = firestore.getUserDataAboutVideos(currentUser!!.uid)
.document(video.videoId).get().await()
if (userDataDocument.exists())
userDataDocument.toObject(UserDataAboutVideo::class.java)!!
else
null
} else null
}
suspend fun <T> Task<T>.await(): T {
return suspendCoroutine { continuation ->
this.addOnCompleteListener { result ->
if (result.result != null && result.isSuccessful)
continuation.resume(result.result!!)
else
continuation.resumeWithException(result.exception?.cause!!)
}
}
}
gildor
12/21/2018, 10:59 AMKulwinder Singh
12/21/2018, 11:12 AMgildor
12/21/2018, 2:08 PM