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
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.
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.
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.
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.
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.
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.
init(params)
@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.
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
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
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'sinit
callback.