= retrofitWS("https://weather-api.herokuapp.com/")
try {
val location = asyncGeocode(ws).await() ?: error("No location :(")
val weather = asyncWeather(location, ws).await()
log("got weather : $weather")
} catch (e: Exception) {
System.err.println("Error is $e")
}
log("finished !")
}
private fun asyncWeather(location: Location, ws: BlockingWeatherWS): Deferred<Weather> = async(CommonPool) {
log("get weather for $location")
ws.weather(location.lat, location.lng, "EN").execute().body()
}
private fun asyncGeocode(ws: BlockingWeatherWS): Deferred<Location?> = async(CommonPool) {
log("get location")
ws.geocode("Toulouse,fr").execute().body().results.first().geometry?.location
} @Test
fun testWeather() = runBlocking {
log("starting ...")
val ws = retrofitWS("https://weather-api.herokuapp.com/")
try {
val location = asyncGeocode(ws).await() ?: error("No location :(")
val weather = asyncWeather(location, ws).await()
log("got weather : $weather")
} catch (e: Exception) {
System.err.println("Error is $e")
}
log("finished !")
}
private fun asyncWeather(location: Location, ws: BlockingWeatherWS): Deferred<Weather> = async(CommonPool) {
log("get weather for $location")
ws.weather(location.lat, location.lng, "EN").execute().body()
}
private fun asyncGeocode(ws: BlockingWeatherWS): Deferred<Location?> = async(CommonPool) {
log("get location")
ws.geocode("Toulouse,fr").execute().body().results.first().geometry?.location
} @Test
fun testWeather() = runBlocking {
log("starting ...")
val ws = retrofitWS("https://weather-api.herokuapp.com/")
try {
val location = asyncGeocode(ws).await() ?: error("No location :(")
val weather = asyncWeather(location, ws).await()
log("got weather : $weather")
} catch (e: Exception) {
System.err.println("Error is $e")
}
log("finished !")
}
private fun asyncWeather(location: Location, ws: BlockingWeatherWS): Deferred<Weather> = async(CommonPool) {
log("get weather for $location")
ws.weather(location.lat, location.lng, "EN").execute().body()
}
private fun asyncGeocode(ws: BlockingWeatherWS): Deferred<Location?> = async(CommonPool) {
log("get location")
ws.geocode("Toulouse,fr").execute().body().results.first().geometry?.location
} @Test
fun testWeather() = runBlocking {
log("starting ...")
val ws = retrofitWS("https://weather-api.herokuapp.com/")
try {
val location = asyncGeocode(ws).await() ?: error("No location :(")
val weather = asyncWeather(location, ws).await()
log("got weather : $weather")
} catch (e: Exception) {
System.err.println("Error is $e")
}
log("finished !")
}
private fun asyncWeather(location: Location, ws: BlockingWeatherWS): Deferred<Weather> = async(CommonPool) {
log("get weather for $location")
ws.weather(location.lat, location.lng, "EN").execute().body()
}
private fun asyncGeocode(ws: BlockingWeatherWS): Deferred<Location?> = async(CommonPool) {
log("get location")
ws.geocode("Toulouse,fr").execute().body().results.first().geometry?.location
} @Test
fun testWeather() = runBlocking {
log("starting ...")
val ws = retrofitWS("https://weather-api.herokuapp.com/")
try {
val location = asyncGeocode(ws).await() ?: error("No location :(")
val weather = asyncWeather(location, ws).await()
log("got weather : $weather")
} catch (e: Exception) {
System.err.println("Error is $e")
}
log("finished !")
}
private fun asyncWeather(location: Location, ws: BlockingWeatherWS): Deferred<Weather> = async(CommonPool) {
log("get weather for $location")
ws.weather(location.lat, location.lng, "EN").execute().body()
}
private fun asyncGeocode(ws: BlockingWeatherWS): Deferred<Location?> = async(CommonPool) {
log("get location")
ws.geocode("Toulouse,fr").execute().body().results.first().geometry?.location
}