Module zotonic_notifier_worker

Simple implementation of an observer/notifier.

Copyright © 2009-2017 Marc Worrell

Behaviours: gen_server.

Authors: Marc Worrell (marc@worrell.nl).

Description

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

Function Index

await/4Subscribe once to a notification, detach after receiving the notification.
await_exact/4
code_change/3Convert process state when code is changed.
detach/3Unsubscribe an owner-pid from an event.
detach_all/2Detach all observers for the owner.
first/4Call all observers till one returns something else than undefined.
foldl/5Do a fold over all observers, prio 1 observers first.
foldr/5Do a fold over all observers, prio 1 observers last.
get_observers/1Return all observers.
get_observers/2Return all observers for a particular event.
handle_call/3Add an observer to an event.
handle_cast/2Trap unknown casts.
handle_info/2Handling all non call/cast messages.
init/1Initiates the server, creates a new observer list.
map/4Call all observers, return the list of answers.
notify1/4Cast the event to the first observer.
notify_async/4Cast the event to all observers.
notify_observer/4Notify an observer of an event.
notify_sync/4Cast the event to all observers.
observe/5Subscribe to an event.
start_link/1Starts the notification server.
start_tests/0Start a notifier server for unit testing.
terminate/2

Function Details

await/4

await(Notifier::zotonic_notifier:notifier(), Event::zotonic_notifier:event(), Msg::atom() | tuple(), Timeout::pos_integer()) -> {ok, tuple() | atom()} | {ok, {pid(), reference()}, tuple() | atom()} | {error, timeout}

Subscribe once to a notification, detach after receiving the notification.

await_exact/4

await_exact(Notifier::zotonic_notifier:notifier(), Event::zotonic_notifier:event(), Msg::term(), Timeout::pos_integer()) -> {ok, term()} | {ok, {pid(), reference()}, term()} | {error, timeout}

code_change/3

code_change(OldVsn::term(), State::#state{name = atom(), observers = ets:tab(), monitors = map(), pid2event = map()}, Extra::term()) -> {ok, #state{name = atom(), observers = ets:tab(), monitors = map(), pid2event = map()}}

Convert process state when code is changed

detach/3

detach(Notifier::zotonic_notifier:notifier(), Event::zotonic_notifier:event(), OwnerPid::pid()) -> ok | {error, term()}

Unsubscribe an owner-pid from an event.

detach_all/2

detach_all(Notifier::zotonic_notifier:notifier(), OwnerPid::pid()) -> ok | {error, term()}

Detach all observers for the owner

first/4

first(Notifier, Event, Msg, ContextArg) -> any()

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

foldl/5

foldl(Notifier, Event, Msg, Acc0, ContextArg) -> any()

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

foldr/5

foldr(Notifier, Event, Msg, Acc0, ContextArg) -> any()

Do a fold over all observers, prio 1 observers last

get_observers/1

get_observers(Notifier::zotonic_notifier:notifier()) -> list()

Return all observers

get_observers/2

get_observers(Notifier::zotonic_notifier:notifier(), Event::zotonic_notifier:event()) -> list()

Return all observers for a particular event

handle_call/3

handle_call(Message, From, State) -> any()

Add an observer to an event

handle_cast/2

handle_cast(Message, State) -> any()

Trap unknown casts

handle_info/2

handle_info(Info, State) -> any()

Handling all non call/cast messages

init/1

init(Name::atom()) -> {ok, #state{name = atom(), observers = ets:tab(), monitors = map(), pid2event = map()}}

Initiates the server, creates a new observer list

map/4

map(Notifier, Event, Msg, ContextArg) -> any()

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

notify1/4

notify1(Notifier, Event, Msg, ContextArg) -> any()

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

notify_async/4

notify_async(Notifier, Event, Msg, ContextArg) -> any()

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

notify_observer/4

notify_observer(Msg, X2, IsCall, ContextArg) -> any()

Notify an observer of an event

notify_sync/4

notify_sync(Notifier, Event, Msg, ContextArg) -> any()

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

observe/5

observe(Notifier::zotonic_notifier:notifier(), Event::zotonic_notifier:event(), Observer::zotonic_notifier:observer(), OwnerPid::pid(), Prio::integer()) -> ok | {error, term()}

Subscribe to an event. Observer is a {M,F} or pid()

start_link/1

start_link(Name::atom()) -> {ok, pid()} | {error, term()}

Starts the notification server

start_tests/0

start_tests() -> {ok, pid()} | {error, term()}

Start a notifier server for unit testing

terminate/2

terminate(Reason::term(), State::#state{name = atom(), observers = ets:tab(), monitors = map(), pid2event = map()}) -> ok


Generated by EDoc