In Clojure I have four primitives to manage concurrency scenarios
My questions is - is there a mature equivalent to each of these in Scala?
Assumptions - I'm going to assume that:
Most of the concurrency constructs you listed for Clojure are based in software transactional memory. Because of that, I think you're basically just asking about STM support in Scala. According to the Akka documentation, the best choice for STM in Scala is ScalaSTM, and they say it's actually going to be included in the Scala Standard Library sometime in the future.
ScalaSTM supports Agents and Refs (which I believe were actually based on the Clojure versions). I think the corollary of an Atom would be the Ref.single type, which is just a ref that you can use outside of an atomic
block.
Depending on your use case, a good substitute for var
would be Java's ThreadLocal
or Scala's DynamicVariable
. Use ThreadLocal
if all you want is thread-local data, but if you actually need dynamic binding, then I think you need DynamicVariable
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With