Does anyone understand why this is considered inva...
# coroutines
r
Does anyone understand why this is considered invalid? If I am instantiating this object within the scope of a suspended function, then this should be supported correct? Or are property getters not allowed to execute suspended code for some reason?
r
created 6 years ago
ūüėě
ty, I will find a different way
d
You'll need to do the suspending bit in the
to()
function body directly then capture the result in anonymous object.
e
instantiating an object in a suspend function doesn't automatically make its function or property getter calls suspend (why should it?), the real question is why
to()
has to be a suspend function? it's just creating an object, no suspend functions are being called so just make it a regular function
suspend property getters aren't supported by Kotlin
the coding conventions state that properties should be ‚Äúcheap to calculate‚ÄĚ and I would go even further and say, they should only contain trivial calculations.
Suspend does not really fit well with this idea of properties.
https://discuss.kotlinlang.org/t/suspend-variables-suspend-val-suspend-var/13142