https://kotlinlang.org logo
#coroutines
Title
# coroutines
e

elizarov

04/19/2017, 10:03 AM
There is no much difference between coroutines and promises for simple stuff. Compare:
Copy code
promise.then {
    it.doSomething() 
}
with
Copy code
launch {
    promise.await().doSomething() 
}
This is quite a liberal example hand-crafted so that both direct usage of promise and coroutines somewhat match in readability. Coroutine benefits accrue with complex processing pipelines (do something async, then something else async, handle exceptions of multiple async actions in one place, etc).
a

adeln

04/19/2017, 10:24 AM
though there’s a difference if you have a chain of two or more and if you ditch promises and go all-in with
suspend
, it becomes much cleaner 🙂
e

elizarov

04/19/2017, 11:08 AM
Yes. It does become cleaner if you ditch promises completely.
a

adeln

04/19/2017, 12:15 PM
wow, pretty cool!
3 Views