z_notifier (zotonic_core v1.0.0-rc.10)

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.
Unsubscribe from an event.
Detach all observers and delete the event
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, Context)
Do a fold over all observers, prio 1 observers last
List all observers for all events for the site.
Return all observers for a particular event
Call all observers, return the list of answers. The prototype of the observer is: f(Msg, Context)
Async cast the event to the first observer. The prototype of the observer is: f(Msg, Context) -> void
Async cast the event to all observers. The prototype of the observer is: f(Msg, Context) -> void
Notify delayed notifications.
Erase queued notifications
Sync cast the event to all observers. The prototype of the observer is: f(Msg, Context) -> void
Subscribe to an event. Observer is a MFA or pid()
Subscribe to an event. Observer is a MFA or pid()

Link to this section Functions

Link to this function

await(Msg, Context)

-spec await(tuple() | atom(), z:context()) ->
         {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(Msg, Timeout, Context)

-spec await(tuple() | atom(), pos_integer(), z:context()) ->
         {ok, tuple() | atom()} | {ok, {pid(), reference()}, tuple() | atom()} | {error, timeout}.
Link to this function

await_exact(Msg, Context)

-spec await_exact(tuple() | atom(), #context{}) ->
               {ok, tuple() | atom()} |
               {ok, {pid(), reference()}, tuple() | atom()} |
               {error, timeout}.
Link to this function

await_exact(Msg, Timeout, Context)

-spec await_exact(tuple() | atom(), pos_integer(), z:context()) ->
               {ok, tuple() | atom()} |
               {ok, {pid(), reference()}, tuple() | atom()} |
               {error, timeout}.
Link to this function

detach(Event, Context)

Unsubscribe from an event.
Link to this function

detach(Event, OwnerPid, Site)

Link to this function

detach_all(Context)

Detach all observers and delete the event
Link to this function

detach_all(OwnerPid, Site)

Link to this function

first(Msg, Context)

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

foldl(Msg, Acc0, Context)

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

foldr(Msg, Acc0, Context)

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

get_observers(Context)

-spec get_observers(z:context()) -> [{atom(), [{integer(), zotonic_notifier:observer()}]}].
List all observers for all events for the site.
Link to this function

get_observers(Event, Site)

Return all observers for a particular event
Link to this function

map(Msg, Context)

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

notify1(Msg, Context)

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

notify(Msg, Context)

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

notify_queue(Context)

Notify delayed notifications.
Link to this function

notify_queue_flush(Context)

Erase queued notifications
Link to this function

notify_sync(Msg, Context)

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

observe(Event, Observer, Context)

Subscribe to an event. Observer is a MFA or pid()
Link to this function

observe(Event, Observer, Priority, Context)

Subscribe to an event. Observer is a MFA or pid()
Link to this function

observe(Event, Observer, OwnerPid, Priority, Site)

-spec observe(zotonic_notifier:event(),
        zotonic_notifier:observer(),
        pid(),
        integer(),
        atom() | z:context()) ->
           ok | {error, term()}.