How do you think Scala can help us to write a distributed memory service like Redis (but multi-thread)?
Scala programming encourages us to use immutable data in order to avoid shared data and race conditions, however in this kind of data storage immutable data can't help us (I think).
Blocking threads would be the solution?
Scala deals with immutable data and mutable data equally well.
Sure it's highly encouraged to use immutable data - for any data which can be shared across threads/actors.
But it's also highly encouraged to use mutable data dedicated to individual threads/actors - i.e. in a context which can never be shared across threads/actors.
A simple high-level concurrency pattern is:
Actor
:Actor
sActor
in a message to AnotherActor
!
and!!
)Future[T]
as part of the initiation. Then specify response handling code viaFuture.onComplete
(or even better viaFuture.flatMap/Map/withFilter/Recover
and theirfor
-comprehension equivalents - which are handy 'monadic'-wrappers aroundonComplete
).