fun LiveData.asFlow(): Flow = channelFlow { offer(value) val observer = Observer { e -> offer(e) } observeForever(observer) invokeOnClose { removeObserver(observer) } } fun Flow.asLiveData(coroutineScope: CoroutineScope): LiveData { return liveData(coroutineScope.coroutineContext + Dispatchers.Default) { collect { emit(it) } } } val searchInput = MutableLiveData() val searchItems: LiveData>> = searchInput .asFlow() .flowOn(Dispatchers.Main) .debounce(100) .transform>> { searchData(it) } .flowOn(Dispatchers.Default) .asLiveData(viewModelScope)