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

Jaroslav

11/05/2018, 1:40 PM
I’m refactoring one interface to change function from suspend to simple. Any ideas how this can be done? Current:
Copy code
Inteface T { suspend fun A: String}

Class S{
  suspend fun B(){
    val result = t.A() 
}
}
I want to change fun A to return Deferred<String> object, but not sure how to change
val result = t.A()
so the result would be the same as if A was suspend function.
j

Joris PZ

11/05/2018, 2:05 PM
I think
val result = t.A().await()
is what you are looking for?
j

Jaroslav

11/05/2018, 2:21 PM
thanks, I’ll try that
z

Zach Klippenstein (he/him) [MOD]

11/05/2018, 5:47 PM
Why do you want A to return a deferred though? It's generally a better practice to write functions as suspend functions and let callers wrap them with
async
if they need it.
j

Jaroslav

11/06/2018, 6:27 AM
it’s an interface that should be implemented in swift, where suspend functions are not exported
2 Views