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

serebit

06/24/2019, 4:31 AM
Why are suspend getters and
suspend operator fun get
not allowed? I assume there's reasoning for them
m

Matej Drobnič

06/24/2019, 7:41 AM
I usually consider getter to be very fast operation. IMO if operation is going to take a while (which most suspending operations do), it should be a function not a getter.
v

vishna

06/24/2019, 7:59 AM
@serebit I wrote myself this a while ago - sadly no getter delegation so 🤷 https://gist.github.com/vishna/1cfaa059304bd2e9b8fabe0292297ce7
e

elizarov

06/24/2019, 10:30 AM
This is indeed one of the reasons we have not added suspended getters/setter just yet. It kind of defeats the intended properties of getter. See Kotlin coding conventions: https://kotlinlang.org/docs/reference/coding-conventions.html#functions-vs-properties
v

vishna

06/24/2019, 10:50 AM
just yet
are there plans to do it?
g

gildor

06/25/2019, 1:20 AM
I still think it would be beneficial to have, it’s more matter of API, it’s especially works good when you have asynchronous lazy using
await
and I would like to have property instead of function to access it Also it’s not necessary slow, it’s just asynchronous
But from other side, I understand that it may require quite a lot of changes, because now you have property with implicit params, and I would rather use existing approach (only function may be suspend), than make compiler even more complicated because of this
e

elizarov

06/25/2019, 5:46 AM
It will be way easier to implement in compiler with upcoming IR backend, but supporting suspend properties in reflection will still be quite a challenge.
18 Views