Hi, are there good `suspend`ing equivalents for `C...
# coroutines
d
Hi, are there good `suspend`ing equivalents for
ConcurrentHashMap
and
ReadWriteLock
in a library anywhere?
z
ensure your map uses a single coroutine to update its values
then it doesn’t matter
d
I can wrap
MutableMap
in a
Mutex
but that's pretty inefficient
z
use a coroutine
d
Hmm. Maybe a quick code sample so I can see what you mean?
z
sure
d
Ahhhh, the actor model.
z
messages to the actor can include a
CompletableDeferred<Map<*,*>>
that you complete when its updated
just make sure your map is immutable 👍
you can also just use a regular channel:
Channel<Message>()
, and launch a coroutine then consumeEach on that channel. Same as using an
actor
but you just access and update your state via the actor’s coroutine, and everything is now thread safe 👍
d
Yup, perfect, thanks!
👍 1
Actor is obsolete...?
m
Actors are marked as deprecated, as the API will be reworked, but the actual idea behind actors isn’t obsolete/deprecated.