guess this is coroutine related.. why can i not do...
# coroutines
n
guess this is coroutine related.. why can i not do
suspend operator get(id: String)
and is there any way to use operator overloading with suspending functions ?
l
It is allowed on a per-case basis. It works with
invoke
operators for example, because it looks like a function call. I think I understand why the
get
one can't suspend as it'd be a bit weird to have square brackets take a long time.
get
operators is almost always used for in-memory structures like arrays, lists…
i
n
seems like i starred the issue in the past and then forgot about it, hah
m
I personally would not like this. If I type in
someDataStructure[10]
I would expect 10th element to be retrieved immediately instead of performing asynchronous operation.
someDataStructure.getAsynchronous(10)
would be more appropriate.
d
I don't see a problem with adding the option. Individuals and teams can have their own rules regarding it.
i
@Matej Drobnič This is a matter of consistency. Currently, some operators can be
suspend
and some cannot. Ideally, all of them should be able to be
suspend
.
a
Suspend does not equal block, so I think suspending call is OK for get operations