Hello how can I transform a callback to a suspend ...
# coroutines
p
Hello how can I transform a callback to a suspend fun?
Copy code
interface Foo<T> {
  fun onSuccess(lis: (T?) -> Unit)
}
I'm trying to do something like this :
Copy code
suspend fun getFoo(): Bar {
   suspendCoroutine<Bar?> { continuation -> 
     val listener = object : Foo<Bar?> {
        override fun onSuccess(lis: (Bar?) -> Unit) { }
     }
}
But I don't know how to return a Bar
j
Your
onSuccess
is probably not a callback, but a function to register a callback. I don't think it's expected that you create an instance of
Foo
yourself here. Could you please share the real-life names for those types? Coroutines aside, how is
Foo
supposed to be used with the callback approach?