MinDelegate v0.1.0 MinDelegate View Source
This MinDelegate module helps to define the client APIs and the server callbacks of GenServer.
@alias
attribute
Use @alias
attribute to specify another name, not state
defmodule Arithmetic do
@alias data
defcast add_op(value1, value2, data) do
data = put_in(data[:add], value1 + value2)
{:reply, data.add, data}
end
end
Link to this section Summary
Functions
Macro defines the client API and the Callback API of GenServer
Macro defines the client API and the Callback API of GenServer
Macro defines the client API and the Callback API of GenServer
Link to this section Functions
Macro defines the client API and the Callback API of GenServer.
The following defcall
macro defines
GenServer.call/3
wrapper for Client and
GenServer.handl_call/3
server callback to receive GenServer.call/3
message.
state
argument specify current state of GenServer.
The format that returns defcall
macro must be the same format that
returns GenServer.handl_call/3
callback.
Examples
defmodule Arithmetic do
defcast add_op(value1, value2, state) do
state = put_in(state[:add], value1 + value2)
{:reply, state.add, state}
end
end
iex> Arithmetic.add_op(pid, value1 = 1, value2 = 3)
Macro defines the client API and the Callback API of GenServer.
The following defcast
macro defines
GenServer.cast/2
wrapper for Client and
GenServer.handl_cast/2
server callback to receive GenServer.cast/2
message
state
argument specify current state of GenServer.
The format that returns defcast
macro must be the same format that
returns GenServer.handl_cast/2
callback.
Examples
defmodule Arithmetic do
defcast minus_op(value1, value2, state) do
state = put_in(state[:minus], value1 - value2)
{:noreply, state}
end
end
iex> Arithmetic.minus_op(pid, value1 = 1, value2 = 3)
Macro defines the client API and the Callback API of GenServer.
The following definfo
macro defines
Kernel.send/2
and Process.send_after/4
wrapper for Client and
GenServer.handl_info/2
server callback to receive info
message
state
argument specify current state of GenServer.
The format that returns definfo
macro must be the same format that
returns GenServer.handl_info/2
callback.
Examples
defmodule Arithmetic do
definfo multiple_op(value1, value2, state) do
state = put_in(state[:multiple], value1 * value2)
{:noreply, state}
end
end
iex> Arithmetic.multiple_op(pid, value1 = 1, value2 = 3)
iex> Arithmetic.multiple_op(pid, value1 = 1, value2 = 3, delay = 3000)