IAmRasputin
12/12/2018, 7:28 PMrunBlocking
exist for the sole purpose of bridging non-blocking with blocking code? If I have a java application that depends on a Kotlin library, would I be able to have the library support coroutines by wrapping the API functions with runBlocking
, or are there other gotchas I need to know so the java application can take advantage of asynchronous code?streetsofboston
12/12/2018, 7:35 PMmain()
), as the entry point into your unit-tests (if your tests use coroutines) and, like you said, bridging non-blocking to blocking code.
The last situation could occur because you need to solve this:
Say you have an interface method that you need to implement.
But this interface method is declared as a regular non suspendable function that needs to wait for a result.
And the code you use to actually need to use to implement that function uses suspendable functions….
That is where you can use runBlocking
future { }
, that return JDK8's CompletableFuture<T>
IAmRasputin
12/12/2018, 8:32 PM