Deepak Gahlot
04/05/2021, 11:46 AM@ExperimentalCoroutinesApi
@VisibleForTesting
val queryChannel = ConflatedBroadcastChannel<String>()
@FlowPreview
@ExperimentalCoroutinesApi
@VisibleForTesting
fun userQuerySearch(query: String) {
viewModelScope.launch {
queryChannel
.asFlow()
.debounce(SEARCH_DELAY_MS)
.mapLatest {
Log.i("mylog", "userQuerySearch: $it")
if (it.length >= MIN_QUERY_LENGTH) {
questionnaireRepoImp.commoditySearch(query = query, sLiveData = searchMasterData)
searchMasterData.postValue(Resource.Loading())
} else {
searchMasterData.postValue(Resource.Success(MasterData()))
}
}
}
corotineScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
questionnaireViewModel.queryChannel.send(value.value)
questionnaireViewModel.userQuerySearch(value.value)
}
queryChannel.consumeEach {
Log.i("mylog", "userQuerySearch: $it")
}
In see that the inputs are being received from the UIDominaezzz
04/05/2021, 12:23 PMquery
as a function argument? You already have the channel, no?debounce
MiSikora
04/05/2021, 12:49 PMlaunchIn
or collect
on your Flow.Deepak Gahlot
04/05/2021, 2:35 PM