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

antoin_m

10/17/2018, 1:59 PM
Thanks @louiscad, so would it be a good solution to wrap the calls in what @enleur suggested here -> https://kotlinlang.slack.com/archives/C1CFAFJSK/p1539784566000100?thread_ts=1539784399.000100&cid=C1CFAFJSK ?
l

louiscad

10/17/2018, 2:01 PM
Or better, adapt callbacks to a suspend function to avoid blocking a thread (which is just wasting resources for the cases where you can avoid it)
a

antoin_m

10/17/2018, 2:03 PM
Yeah, that was more or less the purpose of my first question. How would you adapt a Future#get to a non blocking suspend function?
I feel like I’m missing something
l

louiscad

10/17/2018, 2:04 PM
@antoin_m There's already an integration module, which doesn't use
get
but the callback equivalent I think. Look at kotlinx.coroutines repo in the integration directory
👍 1
a

antoin_m

10/17/2018, 2:08 PM
Ok got it! Thanks 🙂
j

Jonathan

10/17/2018, 2:48 PM
If you have custom code, you can also use `suspendCoroutine`:
Copy code
fun callbackFunction(callback: (String) -> Unit) {
  timer(period = 2000) { callback("Hello world") }
}

suspend fun suspendingUsage(): String {
  return suspendCoroutine { continuation ->
    callbackFunction { result ->
      continuation.resume(result)
    }
  }
}
4 Views