grizzly v0.8.2 Grizzly.Command behaviour View Source

Command is a server managing the overall lifecycle of the execution of a command, from start to completion or timeout.

When starting the execution of a command, the state of the network is checked to see if it is in one of the allowed states for executing this particular command. The allowed states are listed in the pre_states property of the command being started. If the property is absent, the default allowed states are [:idle]. If the network is not in an allowed state, {:error, :network_busy} is returned.

If the started command has an exec_state property, the network state is set to its value for the duration of the execution of the command. If there is none, the network state is unchanged.

If the started command has a post_state property, the network state is set to it after the command execution completes or times out. If there is none, the network state is set to :idle.

If the started command has a timeout property, a timeout is set to its value. If the command does not complete before the timeout expires, the command's execution is stopped and a {:timeout, } message is sent to the process that started the execution of the command.

Link to this section Summary

Link to this section Types

Link to this type

handle_instruction() View Source
handle_instruction() ::
  {:continue, state :: any()}
  | {:done, response :: any()}
  | {:retry, state :: any()}
  | {:send_message, message :: any(), state :: any()}
  | {:queued, state :: any()}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

complete(command) View Source
complete(t()) :: :ok

Link to this function

encode(command) View Source
encode(t()) :: {:ok, binary()} | {:error, Grizzly.Command.EncodeError.t()}

Link to this function

handle_response(command, packet) View Source
handle_response(t(), %Grizzly.Packet{
  body: term(),
  header_extensions: term(),
  raw?: term(),
  seq_number: term(),
  types: term()
}) ::
  {:finished, value :: any()}
  | :continue
  | :retry
  | :queued
  | {:send_message, message :: any()}

Link to this function

start(module, opts) View Source
start(module(), opts :: keyword()) :: GenServer.on_start()

Link to this section Callbacks

Link to this callback

encode(command) View Source
encode(command :: any()) ::
  {:ok, binary()} | {:error, Grizzly.Command.EncodeError.t() | any()}

Link to this callback

handle_response(command, arg2) View Source
handle_response(command :: any(), Grizzly.Packet.t()) :: handle_instruction()

Link to this callback

init(args) View Source
init(args :: term()) :: :ok | {:ok, command :: any()}