test_probe v0.0.2 TestProbe.Message

The %Message{} struct is used to wrap incoming messages. Along with payload it stores type of the message and sender reference if applicable.

%Message{
  type: :any | :call | :cast | :info,   # type of the message
  data: :any | payload,                 # message body
  from: :any | {pid, ref} | nil         # set in case of call
}

It is also used as a pattern when you need to match message.

%Message{}                    # an absolute wildcard, matches any message
%Message{type: :call}         # matches any 'call' message
%Message{data: :hello}        # matches any message with payload == :hello

Link to this section Summary

Functions

Matches two messages. You may use a wildcard :any to specify that any value under a particular key would be considered a match

Link to this section Types

Link to this type t()
t() :: %TestProbe.Message{data: term, from: term, type: atom}

Link to this section Functions

Link to this function match(m1, m2)
match(t, t) :: boolean

Matches two messages. You may use a wildcard :any to specify that any value under a particular key would be considered a match.

Examples

If you’re expecting message by payload, but don’t really care of where it came from:

m = %Message{type: :call, data: "hey", from: {pid, ref}}
match(m, %Message{data: "hey"}) == true