Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
For #3929: Prevent cancellation of concurrent search engine operation
Browse files Browse the repository at this point in the history
  • Loading branch information
csadilek committed Aug 30, 2019
1 parent f2f974f commit ee70ba7
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class SearchEngineManager(
*/
@Synchronized
suspend fun loadAsync(context: Context): Deferred<SearchEngineList> = coroutineScope {
// We might have previous 'load' calls still running; cancel them.
deferredSearchEngines?.cancel()
scope.async {
deferredSearchEngines ?: scope.async {
loadSearchEngines(context)
}.also { deferredSearchEngines = it }
}.also {
deferredSearchEngines = it
}
}

/**
Expand Down Expand Up @@ -77,8 +77,7 @@ class SearchEngineManager(
* a load asynchronously.
*/
private suspend fun getSearchEngineListAsync(context: Context): SearchEngineList =
(deferredSearchEngines ?: loadAsync(context))
.await()
loadAsync(context).await()

/**
* Returns all search engines.
Expand Down

0 comments on commit ee70ba7

Please sign in to comment.