Thanks <@U3ZLHBTLG>, so would it be a good solutio...
# coroutines
a
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&amp;cid=C1CFAFJSK ?
l
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
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
@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
Ok got it! Thanks 🙂
j
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)
    }
  }
}