ExActor.Operations
Macros that can be used for simpler definition of gen_server
operations such as casts or calls.
Summary
defcall(req_def, options \\ [], body) | Defines the call callback clause and a corresponding interface fun |
defcallp(req_def, options \\ [], body) | Same as |
defcast(req_def, options \\ [], body) | Defines the cast callback clause and a corresponding interface fun |
defcastp(req_def, options \\ [], body) | Same as |
definfo(msg, opts \\ [], body) | Defines the info callback clause. Responses work just like with casts |
definit(arg \\ {:_, [], ExActor.Operations}, opts) | Defines the initializer callback |
Macros
Defines the call callback clause and a corresponding interface fun.
Examples:
defcall operation, do: reply(response)
defcall get, state: state, do: reply(state)
defcall inc, state: state, do: set_and_reply(state + 1, response)
# timeout option
defcall long_call, state: state, timeout: :timer.seconds(10), do: ...
# omitting interface fun
defcall operation, export: false, do: ...
# pattern matching
defcall a(1), do: ...
defcall a(2), do: ...
defcall a(x), state: 1, do: ...
defcall a(x), when: x > 1, do: ...
defcall a(x), state: state, when: state > 1, do: ...
defcall a(_), do: ...
Same as defcall/3
but the interface function is private. Can be useful when you need to do pre/post processing in the caller process.
Examples:
def exported_interface(...) do
# do some client side preprocessing here
my_request(...)
# do some client side post processing here
end
# Not available outside of this module
defcallp my_request(...), do: ...
Defines the cast callback clause and a corresponding interface fun.
Examples:
defcast operation, do: noreply
defcast inc(x), state: state, do: new_state(state + x)
# omitting interface fun
defcast operation, export: false, do: ...
# pattern matching
defcast a(1), do: ...
defcast a(2), do: ...
defcast a(x), state: 1, do: ...
defcast a(x), when: x > 1, do: ...
defcast a(x), state: state, when: state > 1, do: ...
defcast a(_), do: ...
Same as defcast/3
but the interface function is private. Can be useful when you need to do pre/post processing in the caller process.
Examples:
def exported_interface(...) do
# do some client side preprocessing here
my_request(...)
# do some client side post processing here
end
# Not available outside of this module
defcastp my_request(...), do: ...
Defines the info callback clause. Responses work just like with casts.
Examples:
definfo :some_message, do: ...
definfo :another_message, state: ..., do: