I just want to say thank you to whomever thought o...
# coroutines
j
I just want to say thank you to whomever thought of this warning.
g
This is recommended convention for Kotlinx.corotuines
Just curious, what is yiour use case for returning UUID in Deferred
j
that’s an api call to get the UUID from an endpoint. Converted the api calls to use coroutines by wrapping them in Deferred<>
this is part of Kotlinx.coroutines doc about this convention
that’s an api call to get the UUID from an endpoint. Converted the api calls to use coroutines by wrapping them in Deferred<>
Why do you need Deferred in this case instead of suspend function?
I’m using that
g
Soon retrofit will support suspend functions
j
I’m looking forward to that, but for now I’m happy with this pattern
not the point I was trying to make when I uploaded that image
g
for now I would just suppress this warning for retrofit interfaces and refactor Deferred to suspend functions later
j
but I appreciate the input
I just like it that the IDE picks up on naming conventions because I know it’s easy to miss those.
g
Yeah, but I wouldn’t use this convention for retrofit services if you use them directly, without wrapper, because soon you will probably refactor it
but it just my IMO
j
hmmm
g
Well, ironically, as @gildor mentioned, this is the exact case where it's better to ignore this warning and not follow the convetion. Because you'll replace it soon, the
suspend
support is already in the retrofit snapshot
j
lol
Thanks for the advice 🙂
😉 1
though they way I did it, once the suspend function is supported, it’ll be really easy to just remove the Deferred<> wrapper and still make the call through the same coroutinescope and things I set up 🤔
g
if you use them always as
api.getUuid().await()
that it will be easy and exactly the same in terms of scopes, lifecycle, dispatchers etc, just remove
Deferred<>
, remove `.await()`and add
suspend
👌 1
g
True, but the
Async
in the name will be redundant and that was the premise of this thread.
1
g
yeah, just one more unnecessary change
s
I found using async named functions make sense only when it launches multiple tasks concurrently over one after the other.
g
@Sam Hm, what do you mean? Async named functions make sense only if it returns Deferred, if it suspend function and under the hood it launches multiple tasks (you can do this using coroutineScope/withContext functions), than no need to use Asyn in name, because it’s just an implementation detail
s
@gildor Yeah, i meant the ones that return Deferred. Caller can leverage concurrency by fun downloadImageAsync : Deferred<T> vs suspend fun downloadImage
g
Yeah, correct, for such case. But I usually don't see a reason for such functions in public API, more flexible provide suspend function and a user of this API easily can wrap it to Deferred on call site if some concurrency is required
s
Okay, yeah that works as well