with coroutines it would be much more pleasant
# javascript
g
with coroutines it would be much more pleasant
The same code but with coroutines + Promise adapter from kotlinx.coroutines
Copy code
private suspend fun loadJsonCoroutines(): String {
    val response = window.fetch(Request("release.json")).await()
    val text = response.text().await()
    return if (response.ok) {
        text
    } else {
        throw Exception("response was not ok, ${response.status}: ${response.statusText}<br/>$text")
    }
}
👍 3