3 ms·
If I've understood this correctly, this sounds very much like erlangs concurrency. Elixr I guess by extension too. Old, tatty code but: https://github.com/Ian
by IanCal 11y ago
If I've understood this correctly, this sounds very much like erlangs concurrency. Elixr I guess by extension too.
Old, tatty code but:
https://github.com/IanCal/semq/blob/master/src/messagequeue.erl https://github.com/IanCal/semq/blob/master/src/messagequeue....
This made message queues that would pause if there was a pop on an empty queue (for long-polling), supports removing everything and if a new 'client' connects while another is waiting for an item sends an error message to the original client. I'm sure there's a neater way of doing it but this sat and ran for quite a while for me and didn't take long to write :)
Generally, the loops are achieved by making an infinitely recursive function call, and you can therefore switch between major behaviours by having multiple functions.
For a quick syntax thing, sending a message is "address ! message" and what I think the "accept" in your code is equivalent to a 'receive' in mine.
You won't have the same type safety, but the general pattern of just blocking and waiting safely is there. It's a fun language, and people seem to be pretty happy with elixr these days too (built on top).
There's some better examples here:
http://learnyousomeerlang.com/the-hitchhikers-guide-to-concurrency http://learnyousomeerlang.com/the-hitchhikers-guide-to-concu...
http://learnyousomeerlang.com/more-on-multiprocessing http://learnyousomeerlang.com/more-on-multiprocessing
- Matthias247 11y agoIt's a little bit different. In Ada it's a real rendezvous. Either the "client" or the "server" task is running. In Erlang the mailbox is asynchronous, which means the server can't make any assumptions about what state the client is in while it works on processing the message and sending it back and the client can't assume that the server is directly working on the message after it put it in his mailbox.