Skip to content

Commit 3c364df

Browse files
authored
Tiny follow-up to async improvements. (#4935)
1 parent 7cd8a6d commit 3c364df

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

app/src/main/java/org/wikipedia/feed/random/RandomClient.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class RandomClient(
3030
cb.error(caught)
3131
}
3232
) {
33-
val list = mutableListOf<RandomCard>()
3433
val deferredSummaries = WikipediaApp.instance.languageState.appLanguageCodes
3534
.filter { !FeedContentType.RANDOM.langCodesDisabled.contains(it) }
3635
.map { lang ->
@@ -49,9 +48,7 @@ class RandomClient(
4948
}
5049
}
5150

52-
val randomCards = deferredSummaries.awaitAll().filterNotNull()
53-
list.addAll(randomCards)
54-
cb.success(list)
51+
cb.success(deferredSummaries.awaitAll().filterNotNull())
5552
}
5653
}
5754

app/src/main/java/org/wikipedia/util/L10nUtil.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.util.SparseArray
77
import android.view.View
88
import androidx.annotation.StringRes
99
import androidx.core.os.ConfigurationCompat
10-
import kotlinx.coroutines.Deferred
1110
import kotlinx.coroutines.Dispatchers
1211
import kotlinx.coroutines.async
1312
import kotlinx.coroutines.awaitAll
@@ -154,14 +153,12 @@ object L10nUtil {
154153
}
155154

156155
// Third, update the extracts from the page/summary endpoint if needed.
157-
val summaryForExtractsDeferred = mutableListOf<Deferred<PageSummary>>()
158156
if (shouldUpdateExtracts) {
159-
summaryForExtractsDeferred.addAll(list.map { pageSummary ->
157+
list.map { pageSummary ->
160158
async {
161159
ServiceFactory.getRest(wikiSite).getPageSummary(null, pageSummary.apiTitle)
162160
}
163-
})
164-
summaryForExtractsDeferred.awaitAll().forEachIndexed { index, pageSummary ->
161+
}.awaitAll().forEachIndexed { index, pageSummary ->
165162
list[index].extract = pageSummary.extract
166163
list[index].extractHtml = pageSummary.extractHtml
167164
}

0 commit comments

Comments
 (0)