ExActor.Operations

Macros that can be used for simpler definition of gen_server operations such as casts or calls.

Source

Summary

defcall(req_def, options \\ [], body)

Defines the call callback clause and a corresponding interface fun

defcallp(req_def, options \\ [], body)

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

defcast(req_def, options \\ [], body)

Defines the cast callback clause and a corresponding interface fun

defcastp(req_def, options \\ [], body)

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

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

defcall(req_def, options \\ [], body)

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: ...
Source
defcallp(req_def, options \\ [], body)

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: ...
Source
defcast(req_def, options \\ [], body)

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: ...
Source
defcastp(req_def, options \\ [], body)

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: ...
Source
definfo(msg, opts \\ [], body)

Defines the info callback clause. Responses work just like with casts.

Examples:

definfo :some_message, do: ...
definfo :another_message, state: ..., do:
Source
definit(arg \\ {:_, [], ExActor.Operations}, opts)

Defines the initializer callback.

Examples:

# ignoring the input argument
definit do: HashSet.new

# using the input argument
definit x do
  x + 1
end

# pattern matching
definit x, when: ..., do: ...
Source