I'm wondering if there's a way to wait for a flow to be complete and return the result inside a suspend function. transactionRepository.getAll(accountId)
returns a flow of transactions
override suspend fun getAccount(accountId: Int): Account {
val account = Account(accountRepository.get(accountId))
transactionRepository.getAll(accountId).mapIterable {
val transaction = Transaction(it)
val category = Category(categoryRepository.get(it.categoryId))
transaction.category = category
transaction.account = account
return@mapIterable transaction
}.collect {
account.transactions = it
}
//TODO: How can i return an account after the flow has been executed?
}
getAll function defined in my repository:
fun getAll(accountId: Int): Flow<List<DatabaseTransaction>>
> and mapIterable is an extension function that basically does a map twice
– DennisVA Sep 01 '21 at 14:04