MarioAriasC / funKTionale

Functional constructs for Kotlin
915 stars 71 forks source link

Better support for coroutines #37

Closed okkero closed 6 years ago

okkero commented 6 years ago

Functions like eitherTry and Try would also be useful when catching exceptions thrown by suspending functions. The current implementations don't support this. For example, I cannot to this:

fun main(args: Array<String>) = runBlocking {
    val a = async<String>(CommonPool) {
        throw Throwable()
    }

    val result = eitherTry {
        a.await()
    }
    println(result)
}

This fails to compile on a.await because we are not in a suspending block.

I see two potential solutions:

MarioAriasC commented 6 years ago

Fix on 1.2

kevinherron commented 6 years ago

I see you marked eitherTry as inline in 1.2, but the reality is almost every function that accepts a lambda callback should be marked inline so that it can be used from a coroutine when the callback might suspend.