Vivek Modi
class KtorCountryApi : NetworkRoute(), KoinComponent { private val httpClient by inject<HttpClient>() suspend fun getCountry(): ApiResponse<KtorCountriesResponse> { val response = httpClient.get { url("xyz") } return apiCall(response) } }
open class NetworkRoute { suspend inline fun <reified T : Any> apiCall(httpResponse: HttpResponse): ApiResponse<T> { return try { ApiResponse.Success(httpResponse.body()) } catch (e: Exception) { ApiResponse.Error() } } }
let ktorApi = KtorCountryApi() ktorApi.getCountry()
'async' call in a function that does not support concurrency
ribesg
suspend
async
A modern programming language that makes developers happier.