Idiomatic Event engine in Scala

I have a problem when some objects change their properties based on some internal logic. For simplicity, imagine a RandomSource object that has a public Int field named Value . An object has its own stream, and sometimes it updates the Value field.

Now other objects in the system are interested in receiving a notification about the Value update. In C #, I could define a companion delegate that is signed by objects and which it occurs when the property is updated.

My question is this: how to do this in Scala? What is the most "idiomatic" solution?

+6
source share
1 answer

Observers are still pretty standard, also known as publisher / listener. You can use your own, or you can use some kind of actor-based solution if you want to receive asynchronous notifications.

On the functional side, this material is most often carried out through a functional reactive framework. There Naftoli Reactive , but Akka also provides a Dataflow , which is a lot of basic concepts.

In addition, this is a field of research on the evolution of Scala, so you can be sure to see more of them.

+1
source

Source: https://habr.com/ru/post/899124/


All Articles