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

Kulwinder Singh

12/13/2018, 9:40 AM
i'm paginating list and loading 5 items each time recyclerview scrolled to last , then using
coroutine
i'm getting more data for each item from network like below
Copy code
private fun onItemsLoaded(videosList: List<BaseVideo>) {
        uiScope.launch {
            val videoAndData = getUserDataForEachVideo(videosList)//suspending function
            adapter.addData(videoAndData)
        }
    }
so here everytime whenever new 5 items loaded then
new
coroutine
is created, so here over the time it will increase created coroutines , i know that coroutines are light weight but is there any other way to solve this problem where i can create a single coroutine and then run my code inside that coroutine instead of creating new coroutine everytime
s

streetsofboston

12/13/2018, 12:04 PM
i

ienoobong

12/14/2018, 11:24 AM
3 Views