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

elizarov

10/01/2018, 1:13 PM
@minivac The proper and idiomatic way is to never use
Deferred
as your return type. Write a suspending function instead:
Copy code
suspend fun doSomething(param: Int): Something {
   code ...
}
See how much more concise it is!
n

nwh

10/01/2018, 8:58 PM
What about in a situation where the result is usually not needed? That means every call has to be wrapped in some type of
launch
or other coroutine control. By returning
Deferred
you make that optional, allowing callers to call and forget about the result.
j

jdemeulenaere

10/01/2018, 9:07 PM
Allowing callers to not handle the result/exception (or make it easier for them to forget) is a bad thing IMO. Not checking the status of a Deferred could actually be something that could be forbidden/warned against when compiling.
n

nwh

10/01/2018, 9:08 PM
Ah, that's true, error propagation is a big concern. I suppose that's the best argument against it.
5 Views