Let me also post here one of nicest examples from ...
# coroutines
e
Let me also post here one of nicest examples from kotlin-fullstack-sample project that showcases the benefits of coroutines:
Copy code
private fun doPostThought() {
        postThoughtPrepare().then({ t ->
            postThought(props.replyTo?.id, state.text, t).then({ thought ->
                onSubmitted(thought)
            }, { onFailed(it) }).catch { onFailed(it) }
        }, { onFailed(it) }).catch { onFailed(it) }
    }
(watch the catch!) gets replaced with:
Copy code
private fun doPostThought() {
        async {
            val token = postThoughtPrepare()
            val thought = postThought(props.replyTo?.id, state.text, token)
            onSubmitted(thought)
        }.catch { err -> onFailed(err) }
    }
👍 4