neuroevolution_events_local (faber_neuroevolution v1.2.4)

View Source

Local event backend using Erlang's pg (process groups).

This is the default backend for single-node or development use. For distributed operation, use neuroevolution_events_macula.

Message Format

Subscribers receive messages in the format: {neuro_event, Topic, Event}

Example

Subscribe to events: neuroevolution_events:subscribe(Topic)

In handle_info: handle_info({neuro_event, Topic, Event}, State) -> io:format("Received ~p on ~p~n", [Event, Topic]), {noreply, State}.

Summary

Functions

Publish an event to all subscribers of a topic.

Start the local event system.

Subscribe a process to a topic.

Unsubscribe a process from a topic.

Functions

publish(Topic, Event)

-spec publish(Topic, Event) -> ok when Topic :: binary(), Event :: term().

Publish an event to all subscribers of a topic.

start()

-spec start() -> ok.

Start the local event system.

This must be called once at application startup to initialize the pg scope. It's safe to call multiple times.

subscribe(Topic, Pid)

-spec subscribe(Topic, Pid) -> ok when Topic :: binary(), Pid :: pid().

Subscribe a process to a topic.

unsubscribe(Topic, Pid)

-spec unsubscribe(Topic, Pid) -> ok when Topic :: binary(), Pid :: pid().

Unsubscribe a process from a topic.