Hi all, I'm writing a server which is essentially an RPC server and I'm using the Tcp and Rpc module of Async.
If i well understand the framework, each incoming connection is bound to a function, which handle the request. But the server, as a whole, has a "shared mutable state": the "shared" part is very simple to be implemented, but the mutable one is not.
To be more concrete the clients will send physical data (temperatures, pressures, electrical quantities, etc.) collected in many customer's plants to the server, which will store the data in many ways (relational DB, raw files, and so on).
The first "shared mutable state" which come in mind is a map of all the opened files: every server callback (serving a client) wants to know if the file is already opened and, if not, open it in append and modify the "global map". Another example is the connection to PostgreSQL or InfluxDB.
I found an old post by Jon Harrop (
https://groups.google.com/forum/#!topic/ocaml-core/dxAVAj33TDE) which exposed more or less the same problem, and an example by Drew Atkin about the use of the Bus module, but I don't really understand how to use Pipes and Buses to avoid a global ref which is of course the easy way to solve the problem.
In Async a mutable global is perfectly safe but I don't really like the paradigm.
Any suggestion about how to solve the problem?