View Source blockade (blockade v0.2.0)
This module defines the public API for the blockade application.
Link to this section Summary
Types
Functions
Adds a handler to an event. The process calling the function will be added to the event group.
Boolean flag to enable or disable the event discarding feature.
Dispatches event asynchronously.
Dispatches event asynchronously with options.
Dispatches event synchronously.
Dispatches event synchronously with options.
Remove a handler from an event.
Sets the priority of the event queue.
Sets the priority of the event queue with options.
Link to this section Types
-type dispatch_opts() :: #{priority => priority(), members => local | global | external | [node()], discard_event => event_discard(), atomic_priority_set => priority()}.
-type event() :: atom().
-type event_discard() :: boolean().
-type event_manager() :: atom().
-type event_payload() :: term().
-type priority() :: integer().
-type priority_opts() :: #{reset_after => integer(), discard_events => event_discard()}.
-type queued_event() :: {event(), event_payload(), dispatch_opts()}.
-type start_up_opts() :: #{name => event_manager(), priority => priority(), discard_events => event_discard()}.
Link to this section Functions
-spec add_handler(event_manager(), event()) -> ok.
Adds a handler to an event. The process calling the function will be added to the event group.
Calling this function multiple times with the same event will add the process to the event group multiple times and the process will receive the event multiple times.-spec child_spec(map()) -> map().
-spec discard_events(event_manager(), event_discard()) -> ok | {error, flag_not_boolean}.
Boolean flag to enable or disable the event discarding feature.
If the flag is set totrue
, the event queue will discard events that have lower priority than the event queue priority.
-spec dispatch(event_manager(), event(), event_payload()) -> ok.
Dispatches event asynchronously.
The event will be dispatched to all the processes that are subscribed to the event.
If no options are passed to the function, the event will be dispatched across the cluster.-spec dispatch(event_manager(), event(), event_payload(), dispatch_opts()) -> ok.
Dispatches event asynchronously with options.
The event will be dispatched to all the processes that are subscribed to the event.-spec dispatch_sync(event_manager(), event(), event_payload()) -> {ok, event_dispatched} | {ok, event_queued} | {ok, event_discarded}.
Dispatches event synchronously.
The function will return when all messages are sent to the subscribed processes. This does not mean that all processes have handled the event because the messages are sent asynchronously.
The event will be dispatched to all the processes that are subscribed to the event.
If no options are passed to the function, the event will be dispatched across the cluster.-spec dispatch_sync(event_manager(), event(), event_payload(), dispatch_opts()) -> {ok, event_dispatched} | {ok, event_queued} | {ok, event_discarded}.
Dispatches event synchronously with options.
The function will return when all messages are sent to the subscribed processes. This does not mean that all processes have handled the event because the messages are sent asynchronously.
The event will be dispatched to all the processes that are subscribed to the event.
If no options are passed to the function, the event will be dispatched across the cluster.-spec get_event_queue(event_manager()) -> {ok, list()}.
-spec get_events(event_manager()) -> {ok, [event()]}.
-spec get_handlers(event_manager(), event()) -> {ok, [pid()]}.
-spec get_priority(event_manager()) -> {ok, priority()}.
-spec local_manager_state(event_manager()) -> {ok, map()}.
-spec prune_event_queue(event_manager()) -> ok.
-spec remove_handler(event_manager(), event()) -> ok | not_joined.
Remove a handler from an event.
The process calling the function will be removed from the event group.-spec set_priority(event_manager(), priority()) -> ok | {error, priority_not_integer}.
Sets the priority of the event queue.
The priority will be propagated to all the nodes in the cluster.
Default priority is0
.
-spec set_priority(event_manager(), priority(), priority_opts()) -> ok | {error, priority_not_integer}.
Sets the priority of the event queue with options.
The priority will be propagated to all the nodes in the cluster.
Optionally the priority can be reset after a certain number of milliseconds and events can be discarded if the priority of the event is lower than the priority of the event queue.
Default priority is0
.
-spec start_link(start_up_opts()) -> {ok, pid()} | ignore | {error, term()}.