james
03/12/2021, 1:43 PMprivate fun loadData() = with(presenterScope) {
listOf(
async {
metadata = transferOtherBank.getMetadata()
},
async {
sources = transferOtherBank.getSourceList()
},
async {
favorites = transferOtherBank.getFavorites()
},
async {
fee = transferOtherBank.getTransactionFee()
},
async {
banks = transferOtherBank.getBanks()
}
)
}
where presenterScope is Coroutine scope provided by moxy2 library (I can attach implementation if it’s necessary)
presenterScope.launch {
loadData().awaitAll()
setName(favorites, banks)
Timber.d("ASSSAS after await")
}
Once some of async fails (getFavorites for example) setName(…) function is never called.
How can I ensure calling of setName(…) despite any error in any async?
Thanks!diesieben07
03/12/2021, 1:45 PMtry {
loadData().awaitAll()
} finally {
// this will run no matter what
}
You could even add a catch
block to catch any exceptions.louiscad
03/12/2021, 1:48 PMwith(presenterScope) { }
with coroutineScope { }
for proper errors propagation.myanmarking
03/15/2021, 10:14 AMlouiscad
03/15/2021, 1:02 PMasync
, and since testing for non golden/happy path is not very popular yet, they don't notice until it's in production.
He'll tell if I was wrong.myanmarking
03/15/2021, 1:10 PM