> I don't quite get how messages and method calls interact.
The term "message passing" is a bit confusing in this case, because it applies
to both objects and actors, but both use a different approach.When you send a message to a regular object, usually a method with the same name is called. For example, when using `process.send` the "send" method in the "process" module is called. This however can change, as objects can implement the method "unknown_message" to handle messages for which no method is explicitly defined.
In case of processes, sending a message is just that: you send a message, this gets put into a special queue, and then it's up to the receiving process to do something with it (whatever that might be). If you want to implement some kind of RPC system you'll need to see what kind of message you have, then dispatch accordingly. Inko's test suite does this using polymorphing: every message the test runner receives implements the "Command" trait, which defines a "run" method. The test runner then simply sends "run" to these command objects, letting them figure things out from there.
> Channels are a great idea! What capabilities (send on channel/receive on
> channel) can you forward to other processes? As Cloud Haskell explain, in
> distributed systems we must not allow send on channel to be forwarded.
I'm not sure if I fully understand this question. A channel in Inko consists out
of two objects: a Sender and a Receiver. The Sender just wraps the PID of the
receiving process, the Receiver is just used for storing the type of the message
at compile time, and providing some methods.As to what you can send: everything that is compatible with the type of the channel. For example:
import std::process
let sender = process.channel!(Integer) lambda (receiver) {
receiver.receive
}
sender.send('foo')
This will fail, because our channel only allows `Integer` values, whereas
"foo" is of type `String`. > Regarding channels, both linear channels and mailbox types for unordered
> interactions are interesting ideas worth looking into.
It is worth mentioning that despite the name "channel" being used for the
method, it's not an actual channel data structure (e.g. like in Go). The
messages are still stored in the mailbox of the receiver, just like when using
`process.send`. Instead, the Sender/Receiver API is just a simple trick that
allows the compiler to know what types of messages are being sent and received.
I called this "channel", because after several hours of thinking I still
couldn't come up with a better name.