Topical.Topic.Server behaviour (topical v0.2.2)

This module defines the bahaviour of a topic.

See Topical.Topic for a usage example.

Link to this section Summary

Callbacks

Invoked before state is captured (after initialisation).

Invoked when a client has executed an action.

Invoked to handle other messages.

Invoked when a client has sent a notification.

Invoked before a client subscribes (but after initialisation).

Invoked after a client unsubscribes (either explicitly or because the process dies).

Invoked when the topic is started to get the initial state.

Invoked when a topic has been stopped.

Functions

Returns a specification to start this module under a supervisor.

Starts a topic server process linked to the current process.

Link to this section Callbacks

Link to this callback

handle_capture(topic, context)

@callback handle_capture(
  topic :: %Topical.Topic{state: term(), updates: term(), value: term()},
  context :: any()
) :: {:ok, %Topical.Topic{state: term(), updates: term(), value: term()}}

Invoked before state is captured (after initialisation).

This callback is optional.

Link to this callback

handle_execute(action, args, topic, context)

@callback handle_execute(
  action :: term(),
  args :: tuple(),
  topic :: %Topical.Topic{state: term(), updates: term(), value: term()},
  context :: any()
) ::
  {:ok, term(), %Topical.Topic{state: term(), updates: term(), value: term()}}

Invoked when a client has executed an action.

This callback is optional. If one is not implemented, the topic will fail if an action is executed.

Link to this callback

handle_info(msg, topic)

@callback handle_info(
  msg :: term(),
  topic :: %Topical.Topic{state: term(), updates: term(), value: term()}
) ::
  {:ok, %Topical.Topic{state: term(), updates: term(), value: term()}}

Invoked to handle other messages.

This callback is optional.

Link to this callback

handle_notify(action, args, topic, context)

@callback handle_notify(
  action :: term(),
  args :: tuple(),
  topic :: %Topical.Topic{state: term(), updates: term(), value: term()},
  context :: any()
) :: {:ok, %Topical.Topic{state: term(), updates: term(), value: term()}}

Invoked when a client has sent a notification.

This callback is optional. If one is not implemented, the topic will fail if a notification is received.

Link to this callback

handle_subscribe(topic, context)

@callback handle_subscribe(
  topic :: %Topical.Topic{state: term(), updates: term(), value: term()},
  context :: any()
) :: {:ok, %Topical.Topic{state: term(), updates: term(), value: term()}}

Invoked before a client subscribes (but after initialisation).

This callback can be used to update the topic, for example (in combination with handle_unsubscribe) to track connected users.

This callback is optional.

Link to this callback

handle_unsubscribe(topic, context)

@callback handle_unsubscribe(
  topic :: %Topical.Topic{state: term(), updates: term(), value: term()},
  context :: any()
) :: {:ok, %Topical.Topic{state: term(), updates: term(), value: term()}}

Invoked after a client unsubscribes (either explicitly or because the process dies).

This callback is optional.

@callback init(params :: [...]) ::
  {:ok, %Topical.Topic{state: term(), updates: term(), value: term()}}
  | {:error, reason :: any()}

Invoked when the topic is started to get the initial state.

params are the values associated with the placeholders in the route.

Link to this callback

terminate(reason, topic)

@callback terminate(
  reason :: term(),
  topic :: %Topical.Topic{state: term(), updates: term(), value: term()}
) :: term()

Invoked when a topic has been stopped.

This callback is optional.

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

start_link(options)

Starts a topic server process linked to the current process.

options

Options

  • :module - the module that implements the topic behaviour.
  • :init_arg - the argument passed to the topic's init callback.