Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions: Process Function Matching #25

Closed
pwhittin opened this issue Aug 16, 2017 · 1 comment
Closed

Questions: Process Function Matching #25

pwhittin opened this issue Aug 16, 2017 · 1 comment
Labels

Comments

@pwhittin
Copy link
Collaborator

pwhittin commented Aug 16, 2017

Consider a process function like:

(op/proc-defn
  event-loop
  [server event-name to-go]
  (op/receive!
    [server ref :cancel] (op/! server [ref :ok])
    (after to-go (op/! server [:done event-name])))) 

A couple of questions:

  1. Will the match [server ref :cancel] only match messages from the specific value of server passed to event-loop, any value of ref and :cancel?
  2. What happens to non-matching messages that might be sent to event-loop?
  3. Should one do something to handle non-matching messages?
@sskorokhodov
Copy link
Collaborator

sskorokhodov commented Aug 20, 2017

  1. Will the match [server ref :cancel] only match messages from the specific value of server passed to event-loop, any value of ref and :cancel?

Yes. It works exactly like clojure/core.match does.

  1. What happens to non-matching messages that might be sent to event-loop?

If message doesn't match, receive! will throw IllegalArgumentException. Once again as clojure/core.match does.

  1. Should one do something to handle non-matching messages?

It depends on what desired behavior is:

  1. The default way is to simply skip handling of unexpected messages and crash. Unexpected messages are usually sing of bugs. This way works if everything is linked properly.
  2. Sometimes one expects arbitrary messages and wants to tolerate them. In such cases "catch all" clause at the end is the way to go.

It's not a final decision, but I really want to add "selective receive" working the same way as erlang's receive does. Using selective receive instead of receive! one can wait for a specific message leaving other messages untouched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants