Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for coroutines #37

Closed
okkero opened this issue Sep 17, 2017 · 2 comments
Closed

Better support for coroutines #37

okkero opened this issue Sep 17, 2017 · 2 comments
Assignees

Comments

@okkero
Copy link

okkero commented Sep 17, 2017

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:

  • Add new functions (or change existing signatures) to support coroutines. E.g: eitherTry becomes suspend fun <T> eitherTry(body: suspend () -> T): Either<Throwable, T>
  • Simply mark these functions inline.
@MarioAriasC MarioAriasC self-assigned this Sep 20, 2017
@MarioAriasC
Copy link
Owner

Fix on 1.2

@kevinherron
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants