Why are suspend getters and `suspend operator fun ...
# coroutines
s
Why are suspend getters and
suspend operator fun get
not allowed? I assume there's reasoning for them
m
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
@serebit I wrote myself this a while ago - sadly no getter delegation so 🤷 https://gist.github.com/vishna/1cfaa059304bd2e9b8fabe0292297ce7
e
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
just yet
are there plans to do it?
g
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
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.