3 ms·
I understand that its actor model pursues very different ideas from Erlang and is therefore very limited and bare bones, basically allowing only per actor event
by zzzcpan 8y ago
I understand that its actor model pursues very different ideas from Erlang and is therefore very limited and bare bones, basically allowing only per actor event handlers (behaviors in Pony terms). How does it work in practice, do you use higher order functions to construct basic flows? Like doing something, then entering receive loop for certain messages and making sure no other handler gets called to mess with the state until we are in receive loop for this type of message, then doing something else and entering another receive loop and so on.
- spooneybarger 8y agoSorry, I don't understand your question but I'm going to answer it as best as I understand. Apologies if it ends up being a non-answer. There's a good talk by Scott Fritchie on the differences between Pony and Erlang that I would suggest. talk: https://www.youtube.com/watch?v=uv-3ptTD8hg&feature=youtu.be https://www.youtube.com/watch?v=uv-3ptTD8hg&feature=youtu.be slides: https://github.com/slfritchie/wide-world-of-actors https://github.com/slfritchie/wide-world-of-actors Like Erlang, each Pony actor has a mailbox that is processed in a serial fashion so that only one message is being processed. In Erlang, you have selective receive that allows you to receive messages out of order that they arrived. Pony has causal messaging where each message has to be handled in the order it was received. Otherwise they are same in terms of how received messages are handled. There's no `receive` in Pony as the behaviors are called directly. I would not call that "very limited and bare bones". Its different.
- aturley 8y agoPony's model is different than Erlang's, so trying to think of it in terms of Erlang's model ("entering receive loop") may not be helpful when trying to understand it. The Pony runtime takes care of scheduling an actor to run when there is a message for that actor. The actor runs through the behavior and then waits to be scheduled again by the runtime when another message is available. If you want to filter messages you need to arrange a way to do that in your code. There's no way to inspect the message queue.
- abritinthebay 8y agoSo kind of like the RabbitMQ worker/message/job dynamic?
- aturley 8y agoPony uses a queue for storing messages that have been sent to an actor, so that's probably a reasonable way to start thinking about it. I'm not sure how far I would stretch this comparison, though. :)
- spooneybarger 8y agoThis might be a little hard to converse on over HN comment. If you stop by the #ponylang channel on freenode, it would be easier to discuss as there would probably be a lot of back and forth.
- zzzcpan 8y agoI get it, it's like event driven programming with static event handlers per actor. Where you can't express a wait for a specific message directly in the body of the function. But you still have to do it somehow, which is what my question was about, how do people do it in Pony. Typically in event driven systems to do this either nested callbacks are used or higher order programming (futures/promises, etc).
- spooneybarger 8y agoYou can use callbacks, state machines, promises. All are available as options to use.