I've been trying to write a network storage access...
# coroutines
n
I've been trying to write a network storage access library and I have to admit the lack of suspending properties is making the syntax overly complex. I'd love to be able to do something like:
Copy code
suspend val size: Long
    get() = remoteServer.getFileSize(this)
Instead, I'm stuck with this:
Copy code
suspend fun getSize() = remoteServer.getFileSize(this)
So users have to do
file.getSize()
instead of just
file.size
😞 There's a discussion in the forums about this but there has been no interaction from the JetBrains team. Are there any plans to support this?
g
file.size()
vs
file.size
is not so much different IMO But agree, suspend properties would be a good addition
n
Wow.... That's actually a good idea haha...
A part of me is still stuck in the Java world where everything is
get
this and
set
that
😅 1
b
IIRC, the idiomatic Kotlin way is for properties to be very uncosty to access multiple times
g
it can be uncosty even with suspend just asyncronous, also suspend properties really needed when you convert blocking code with properties to non-blocking and want to keep old API
b
I was just referring to the
remoteServer....
in the OP implementation. I was more referring to network usually being considered more costy
g
Yes, I’m not sure about particular use case. But stdlib File.size also does IO access, so there are no strict rules
b
Yeah, IO in general is fairly costy relative to basic in-memory/compute (which is usually what I've seen properties recommended for at most). Obviously it's just an API either way though