I've got the following class:
class SomeApiRemoteSource (private var someApi: SomeApi)
{
private val someData = MutableLiveData<Map<String, String>>()
init
{
GlobalScope.launch(Dispatchers.IO)
{
try
{
val response = someApi.getSomeData(SomeApi.API_KEY).awaitResponse()
if(response.isSuccessful)
someData.postValue(response.body()?.data)
else
someData.postValue(emptyMap())
}
catch (e: Exception)
{
Log.e("ds error", e.message!!)
someData.postValue(emptyMap())
}
}
}
fun getSomeData(): MutableLiveData<Map<String, String>>
{
return someData
}
}
Everything works fine, but is there a way to get the same result without using the init? What if I need to run another API getter call? Should I just run another coroutine right below that 1st one? That seems inefficient.