4 ms·
Why it is necessary to discard messages? Isn't it a sign of bad design when resources have to be spend to create and pass a message that is ultimately discarded
by fpoling 9y ago
Why it is necessary to discard messages? Isn't it a sign of bad design when resources have to be spend to create and pass a message that is ultimately discarded?
- ramchip 9y agoI think it’s just a bit badly worded. You don’t normally throw them away, you leave them in the queue for later. For instance if you have a process that gets requests and writes stuff to DB, while processing a request you can send a message to the DB, then use a selective receive to match on the response from the DB while ignoring all other messages (you’ll deal with them later i.e. when you fetch the next request to process).
- spiralx 9y agoProcesses discard messages that they aren't interested in, that doesn't mean another process isn't.
- fpoling 9y agoErlang has one message queue per prosess. So if a process discards the message, the message cannot be available for other processes. Moreover, as Erlang does not have message broadcast and all messages the process receives were explicitly sent to it, the process can not receive messages accidentally.