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

asad.awadia

02/23/2018, 12:40 AM
@elizarov Just out of curiosity - how does one go about adding support for 'suspend' functions to their own interface of their library - dunno if the question makes sense --- https://twitter.com/JakeWharton/status/964556938322341894
👍 1
g

gildor

02/23/2018, 1:52 AM
What do you mean? Of course only one who wants to use suspend Retrofit method would add it to interface. This tweet about support of such approach from side of Retrofit
a

asad.awadia

02/23/2018, 1:53 AM
Right yeah thats what I mean - what would the support from retrofit's side look like
g

gildor

02/23/2018, 1:54 AM
Retrofit uses reflection and creates Proxy instances. So I suppose it should somehow detect suspend functions and generate proper Proxy instance for suspend functions
j

jw

02/23/2018, 3:14 AM
Yes, that. It's a mechanism for detecting the Continuation parameter and hooking it up.
Except in a general way and not just hardcoding explicit support
g

gildor

02/23/2018, 3:20 AM
In a general way? What do you mean? Allow to support not only kotlin.coroutines Continuations?
j

jw

02/23/2018, 3:21 AM
Retrofit 1 allowed a callback as the last parameter of a method signature. So the idea is to build a mechanism similar to CallAdapters that allows adapting the last parameter into another type.
So you'd install a CallbackAdapter that adapted a Continuation into retrofit's Callback which was then enqueued automatically before returning
g

gildor

02/23/2018, 3:22 AM
I see. And then just provide this parameter adapter for coroutines continuation
yes, got it
2 Views