Umbra v0.1.0 Umbra.Operations View Source
This modules is the facade for the Umbra.CodeGenerator module.
It defines all macros definit/2, defcall/3, defcast/3, definfo/3 and defcontinue/3.
Link to this section Summary
Functions
Generate the GenServer GenServer.handle_call/3 callback and
a client method to call the function through GenServer.call/2.
Generate the GenServer GenServer.handle_cast/2 callback and
a client method to call the function through GenServer.cast/2.
Generate the GenServer GenServer.handle_continue/2 callback.
Generate the GenServer GenServer.handle_info/2 callback and
a client method to call the function through Process.send/3.
Generate the GenServer GenServer.init/1 callback.
Link to this section Functions
Specs
Generate the GenServer GenServer.handle_call/3 callback and
a client method to call the function through GenServer.call/2.
By default generates the client and server function in public.
Options
- private:
boolean(), default tofalse - when:
a statement - server:
boolean(), default totrue - client:
boolean(), default totrue - state:
a statement, default to_state - from:
a statement, default to_from
Example
Defining:
defcall {:compute, a, b}, do: {:reply, a + b, nil}Will generate:
def get_state(pid_or_state, a, b) do
{:ok, GenServer.call(pid_or_state, {:compute, a, b})
end
def handle_call({:compute, a, b}, _from, _state) do
{:reply, a + b, nil}
end Specs
Generate the GenServer GenServer.handle_cast/2 callback and
a client method to call the function through GenServer.cast/2.
By default generates the client and server function in public.
Options
- private:
boolean(), default tofalse - when:
a statement - server:
boolean(), default totrue - client:
boolean(), default totrue - state:
a statement, default to_state
Example
Defining:
defcast {:set_state, %{id: id, name: name} = new_state}, do: {:noreply, new_state}Will generate:
def set_state(pid, %{id: _id, name: _name} = new_state) do
GenServer.cast(pid, {:set_state, new_state})
end
def handle_cast({:set_state, %{id: id, name: name} = new_state}, _state) do
{:noreply, new_state}
end Specs
Generate the GenServer GenServer.handle_continue/2 callback.
It is server-side only, so no client method will be defined.
Options
- when:
a statement - state:
a statement, default to_state
Example
Defining:
defcontinue {:send_to_process, pid, result}, state: state do
Process.send(pid, result)
{:noreply, state}
endWill generate:
def handle_continue({:send_to_process, pid, result}, state) do
Process.send(pid, result)
{:noreply, state}
end Specs
Generate the GenServer GenServer.handle_info/2 callback and
a client method to call the function through Process.send/3.
By default only generate the server-side function. The client-side function can be useful sometimes.
Options
- private:
boolean(), default tofalse - when:
a statement - server:
boolean(), default totrue - client:
boolean(), default tofalse - state:
a statement, default to_state
Example
Defining:
definfo {:ping}, client: true, state: state do
IO.puts(:pong)
{:noreply, state}
endWill generate:
def ping(pid) do
Process.send(pid, {:ping})
end
def handle_info({:ping}, state) do
IO.puts(:pong)
{:noreply, state}
end Specs
Generate the GenServer GenServer.init/1 callback.
It is server-side only, so no client method will be defined.
Options
- when:
a statement - state:
a statement, default to_state
Example
Defining:
definit state: state, do: {:ok, state}Will generate:
def init(state: state) do
{:ok, state}
end