zotonic_notifier_worker (zotonic_notifier v1.0.0-rc.17)
Simple implementation of an observer/notifier. Relays events to observers of that event. Also implements map and fold operations over the observers.
Summary
Functions
Subscribe once to a notification, detach after receiving the notification.
Convert process state when code is changed
Unsubscribe an owner-pid from an event.
Detach all observers for the owner
Call all observers till one returns something else than undefined. The prototype of the observer is: f(Msg, Context)
Do a fold over all observers, prio 1 observers first. The prototype of the observer is: f(Msg, Acc, ContextArg)
Do a fold over all observers, prio 1 observers last
Return all observers
Return all observers for a particular event
Add an observer to an event
Trap unknown casts
Handling all non call/cast messages
Initiates the server, creates a new observer list
Call all observers, return the list of answers. The prototype of the observer is: f(Msg, ContextArg)
Cast the event to the first observer. The prototype of the observer is: f(Msg, Context) -> void
Cast the event to all observers. The prototype of the observer is: f(Msg, Context) -> void
Notify an observer of an event
Cast the event to all observers. The prototype of the observer is: f(Msg, Context) -> void
Subscribe to an event. Observer is a {M,F} or pid()
Starts the notification server
Start a notifier server for unit testing
Functions
-spec await(zotonic_notifier:notifier(), zotonic_notifier:event(), atom() | tuple(), pos_integer()) -> {ok, tuple() | atom()} | {ok, {pid(), reference()}, tuple() | atom()} | {error, timeout}.
Subscribe once to a notification, detach after receiving the notification.
-spec await_exact(zotonic_notifier:notifier(), zotonic_notifier:event(), term(), pos_integer()) -> {ok, term()} | {ok, {pid(), reference()}, term()} | {error, timeout}.
-spec code_change(term(), #state{name :: atom(), observers :: ets:tab(), monitors :: map(), pid2event :: map()}, term()) -> {ok, #state{name :: atom(), observers :: ets:tab(), monitors :: map(), pid2event :: map()}}.
Convert process state when code is changed
-spec detach(zotonic_notifier:notifier(), zotonic_notifier:event(), pid()) -> ok.
Unsubscribe an owner-pid from an event.
-spec detach_all(zotonic_notifier:notifier(), pid()) -> ok.
Detach all observers for the owner
Call all observers till one returns something else than undefined. The prototype of the observer is: f(Msg, Context)
Do a fold over all observers, prio 1 observers first. The prototype of the observer is: f(Msg, Acc, ContextArg)
Do a fold over all observers, prio 1 observers last
-spec get_observers(zotonic_notifier:notifier()) -> list().
Return all observers
-spec get_observers(zotonic_notifier:notifier(), zotonic_notifier:event()) -> list().
Return all observers for a particular event
Add an observer to an event
Trap unknown casts
Handling all non call/cast messages
-spec init(atom()) -> {ok, #state{name :: atom(), observers :: ets:tab(), monitors :: map(), pid2event :: map()}}.
Initiates the server, creates a new observer list
Call all observers, return the list of answers. The prototype of the observer is: f(Msg, ContextArg)
Cast the event to the first observer. The prototype of the observer is: f(Msg, Context) -> void
Cast the event to all observers. The prototype of the observer is: f(Msg, Context) -> void
Notify an observer of an event
Cast the event to all observers. The prototype of the observer is: f(Msg, Context) -> void
-spec observe(zotonic_notifier:notifier(), zotonic_notifier:event(), zotonic_notifier:observer(), pid(), integer()) -> ok | {error, term()}.
Subscribe to an event. Observer is a {M,F} or pid()
-spec start_link(Name :: atom()) -> gen_server:start_ret().
Starts the notification server
-spec start_tests() -> gen_server:start_ret().
Start a notifier server for unit testing