From 4615c662b4a826a2ae388f06fb864bafd460af11 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 11 Apr 2023 18:28:13 +0530 Subject: [PATCH] Run load tasks concurrently. --- .../github/libretube/ui/fragments/HomeFragment.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt index 96dfe8777..560458f1b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt @@ -27,6 +27,8 @@ import com.github.libretube.ui.adapters.PlaylistsAdapter import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.models.SubscriptionsViewModel import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -80,10 +82,12 @@ class HomeFragment : Fragment() { private fun fetchHomeFeed() { lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.CREATED) { - loadTrending() - loadBookmarks() - loadFeed() - loadPlaylists() + awaitAll( + async { loadTrending() }, + async { loadBookmarks() }, + async { loadFeed() }, + async { loadPlaylists() } + ) } } }