zotonic_notifier_worker (zotonic_notifier v1.0.0-rc.12)

Simple implementation of an observer/notifier. Relays events to observers of that event. Also implements map and fold operations over the observers.

Link to this section 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

Link to this section Functions

Link to this function

await(Notifier, Event, Msg, Timeout)

-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.
Link to this function

await_exact(Notifier, Event, Msg, Timeout)

-spec await_exact(zotonic_notifier:notifier(), zotonic_notifier:event(), term(), pos_integer()) ->
               {ok, term()} | {ok, {pid(), reference()}, term()} | {error, timeout}.
Link to this function

code_change(OldVsn, State, Extra)

-spec code_change(term(), #state{}, term()) -> {ok, #state{}}.
Convert process state when code is changed
Link to this function

detach(Notifier, Event, OwnerPid)

-spec detach(zotonic_notifier:notifier(), zotonic_notifier:event(), pid()) -> ok | {error, term()}.
Unsubscribe an owner-pid from an event.
Link to this function

detach_all(Notifier, OwnerPid)

-spec detach_all(zotonic_notifier:notifier(), pid()) -> ok | {error, term()}.
Detach all observers for the owner
Link to this function

first(Notifier, Event, Msg, ContextArg)

Call all observers till one returns something else than undefined. The prototype of the observer is: f(Msg, Context)
Link to this function

foldl(Notifier, Event, Msg, Acc0, ContextArg)

Do a fold over all observers, prio 1 observers first. The prototype of the observer is: f(Msg, Acc, ContextArg)
Link to this function

foldr(Notifier, Event, Msg, Acc0, ContextArg)

Do a fold over all observers, prio 1 observers last
Link to this function

get_observers(Notifier)

-spec get_observers(zotonic_notifier:notifier()) -> list().
Return all observers
Link to this function

get_observers(Notifier, Event)

-spec get_observers(zotonic_notifier:notifier(), zotonic_notifier:event()) -> list().
Return all observers for a particular event
Link to this function

handle_call(Message, From, State)

Add an observer to an event
Link to this function

handle_cast(Message, State)

Trap unknown casts
Link to this function

handle_info(Info, State)

Handling all non call/cast messages
-spec init(atom()) -> {ok, #state{}}.
Initiates the server, creates a new observer list
Link to this function

map(Notifier, Event, Msg, ContextArg)

Call all observers, return the list of answers. The prototype of the observer is: f(Msg, ContextArg)
Link to this function

notify1(Notifier, Event, Msg, ContextArg)

Cast the event to the first observer. The prototype of the observer is: f(Msg, Context) -> void
Link to this function

notify_async(Notifier, Event, Msg, ContextArg)

Cast the event to all observers. The prototype of the observer is: f(Msg, Context) -> void
Link to this function

notify_observer(Msg, _, IsCall, ContextArg)

Notify an observer of an event
Link to this function

notify_sync(Notifier, Event, Msg, ContextArg)

Cast the event to all observers. The prototype of the observer is: f(Msg, Context) -> void
Link to this function

observe(Notifier, Event, Observer, OwnerPid, Prio)

-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()
Link to this function

start_link(Name)

-spec start_link(Name :: atom()) -> {ok, pid()} | {error, term()}.
Starts the notification server
-spec start_tests() -> {ok, pid()} | {error, term()}.
Start a notifier server for unit testing
Link to this function

terminate(Reason, State)

-spec terminate(term(), #state{}) -> ok.