Skip to content

Instantly share code, notes, and snippets.

private suspend fun getWeatherDataByCity(cityName: String) {
CoroutineScope(Dispatchers.IO).launch {
val weatherData = getWeatherData(cityName)
withContext(Dispatchers.Main){
someLiveData.value = weatherData
}
}
}
private suspend fun getWeatherDataByCity(cityName: String) {
val deferredResult = CoroutineScope(Dispatchers.IO).async {
// do what you need here
}
deferredResult.await()
}
private suspend fun getWeatherDataByCity(cityName: String) {
CoroutineScope(Dispatchers.IO).async {
// do what you need here
}
}
private suspend fun getWeatherDataByCity(cityName: String) {
CoroutineScope(Dispatchers.IO).launch {
// do what you need here
}
}
@garodrigues
garodrigues / SuspendExample.kt
Last active March 26, 2020 15:02
Suspend function
private suspend fun getWeatherDataByCity(cityName: String) {
getWeatherData(cityName)
}