Skip to content

How to do a Kotlin style suspend? #92

Answered by rssh
TwoClocks asked this question in Q&A
Discussion options

You must be logged in to vote

In kotlin, you can only suspend from a coroutine context, but you can resume from anywhere.

But you can't receive results. In such a way, Scala offers the same capabilities. (i.e., you can call a method on monad, but you can't read the result outside monad).

The direct use of Continuation in your example is problematic. If you use Continuation, then you need Continuation support from the JVM (which, in fact, is Loom) or some monadic continuation interface (IO, ContT, etc.).

If only you need to run FFI in a separate thread, then using Continuation is overkill. For FFI calls you can create Future with custom execution context, which evaluates in the dedicated thread and has interface like:

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@rssh
Comment options

@TwoClocks
Comment options

@rssh
Comment options

Answer selected by TwoClocks
@TwoClocks
Comment options

@rssh
Comment options

@rssh
Comment options

@TwoClocks
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants