Module z_notifier

Simple implementation of an observer/notifier.

Copyright 2009 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

code_change/3Convert process state when code is changed.
detach/3Unsubscribe from an event.
detach_all/2Detach all observers and delete the event.
first/2Call all observers till one returns something else than undefined.
foldl/3Do a fold over all observers, prio 1 observers first.
foldr/3Do a fold over all observers, prio 1 observers last.
get_observers/2Return all observers for a particular event.
handle_call/3Add an observer to an event.
handle_cast/2Trap unknown casts.
handle_info/2Handle timer ticks.
init/1Initiates the server, creates a new observer list.
map/2Call all observers, return the list of answers.
notify/2Cast the event to all observers.
notify1/2Cast the event to the first observer.
notify_observer/4Notify an observer of an event.
observe/3Subscribe to an event.
observe/4Subscribe to an event.
start_link/1Starts the notification server.
start_tests/0Start a notifier server for unit testing.
terminate/2This function is called by a gen_server when it is about to terminate.

Function Details

code_change/3

code_change(OldVsn, State, Extra) -> {ok, NewState}

Convert process state when code is changed

detach/3

detach(Event, Observer, Context) -> any()

Unsubscribe from an event. Observer is a {M,F} or pid()

detach_all/2

detach_all(Event, Context) -> any()

Detach all observers and delete the event

first/2

first(Msg, Context) -> any()

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

foldl/3

foldl(Msg, Acc0, Context) -> any()

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

foldr/3

foldr(Msg, Acc0, Context) -> any()

Do a fold over all observers, prio 1 observers last

get_observers/2

get_observers(Msg, Context) -> any()

Return all observers for a particular event

handle_call/3

handle_call(Message::Request, From, State) -> {reply, Reply, State} | {reply, Reply, State, Timeout} | {noreply, State} | {noreply, State, Timeout} | {stop, Reason, Reply, State} | {stop, Reason, State}

Add an observer to an event

handle_cast/2

handle_cast(Message::Msg, State) -> {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}

Trap unknown casts

handle_info/2

handle_info(Info, State) -> {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}

Handle timer ticks

init/1

init(Args) -> {ok, State} | {ok, State, Timeout} | ignore | {stop, Reason}

Initiates the server, creates a new observer list

map/2

map(Msg, Context) -> any()

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

notify/2

notify(Msg, Context) -> any()

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

notify1/2

notify1(Msg, Context) -> any()

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

notify_observer/4

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

Notify an observer of an event

observe/3

observe(Event, Observer, Context) -> any()

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

observe/4

observe(Event, Observer, Priority, Context) -> any()

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

start_link/1

start_link(SiteProps) -> {ok, Pid} | ignore | {error, Error}

Starts the notification server

start_tests/0

start_tests() -> any()

Start a notifier server for unit testing

terminate/2

terminate(Reason, State) -> void()

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.


Generated by EDoc, Oct 22 2014, 21:45:08.