launch
function returns a Job
. You can keep a reference to it and check its isActive
property, but that is not how well-architected UI applications are usually written. Instead, you typically have some observable property (or LiveData, or Rx subject, or conflated broadcast channel, or whatever else you are using in your UI models to track ongoing asynchronous operations) and write something like:
loadingData = true
launch {
try {
doLoadData()
} finally {
loadingData = false
}
}
A larger application would usually define this loadingData
property in some base class of its view models (or whatever else — depending on the architecture) and provide some convenience function to set and reset it.