Flow

fun insert(categoryName: String) {
viewModelScope.launch {
val category =
CategoryData(0,
categoryName,
System.currentTimeMillis(),
System.currentTimeMillis())
AppDatabase.getCategoryDao(getApplication()).insert(category)
Log.d("CategoryViewModel", "insert :$category")
}
}

fun getAll(): Flow> {
    return AppDatabase.getCategoryDao(getApplication())
        .getAll()
        .catch { e -> e.printStackTrace() }
        .flowOn(Dispatchers.IO)
}

你可能感兴趣的:(Flow)