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

poohbar

01/01/2019, 4:22 PM
runBlocking
is a bridge between the coroutine "world" and normal non-coroutine "world". Are there any other "bridges"? I am looking for
runNonBlocking
.
b

bdawg.io

01/01/2019, 4:52 PM
You can also use JDK APIs like
CompletableFuture
via the
kotlinx-coroutines-jdk8
module
Copy code
val myFuture = future<Int> { 
    delay(100)
    100
}
Note: the coroutine APIs, including
launch
, spend a lot of time ensuring deep cancellation and handled failures. They’re definitely my go-to over futures.
p

poohbar

01/01/2019, 8:25 PM
hmm.. didn't know about this module.. will probably try to learn the native kotlin way since my project is 100% kotlin
d

dave08

01/02/2019, 3:47 AM
async {}
is also another bridge when you need the result (or to bubble up an exception thrown, since launch will just "swallow" the exception...), just learn about structured concurrency before you start with them, so you don't leak your coroutines.
6 Views