get all suggestions without coroutines

This commit is contained in:
Helium314 2025-05-26 20:35:07 +02:00 committed by GitHub
parent deec4d1f98
commit 0a9c9fdab8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -469,18 +469,16 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
val proximityInfoHandle = keyboard.proximityInfo.nativeProximityInfo val proximityInfoHandle = keyboard.proximityInfo.nativeProximityInfo
val weightOfLangModelVsSpatialModel = floatArrayOf(Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL) val weightOfLangModelVsSpatialModel = floatArrayOf(Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL)
val deferredSuggestions = dictionaryGroups.map { val suggestions = dictionaryGroups.map {
scope.async {
// todo: if the order does not matter, we could add the suggestions right away without awaitAll first // todo: if the order does not matter, we could add the suggestions right away without awaitAll first
getSuggestions(composedData, ngramContext, settingsValuesForSuggestion, sessionId, getSuggestions(composedData, ngramContext, settingsValuesForSuggestion, sessionId,
proximityInfoHandle, weightOfLangModelVsSpatialModel, it) proximityInfoHandle, weightOfLangModelVsSpatialModel, it)
} }
}
val suggestionResults = SuggestionResults( val suggestionResults = SuggestionResults(
SuggestedWords.MAX_SUGGESTIONS, ngramContext.isBeginningOfSentenceContext, SuggestedWords.MAX_SUGGESTIONS, ngramContext.isBeginningOfSentenceContext,
false false
) )
runBlocking { deferredSuggestions.awaitAll() }.forEach { suggestions.forEach {
suggestionResults.addAll(it) suggestionResults.addAll(it)
suggestionResults.mRawSuggestions?.addAll(it) suggestionResults.mRawSuggestions?.addAll(it)
} }