observer

Publish/Subscribe Event Pattern

Functions

FunctionDescription
obs_newCreate an event bus.
obs_find_topicInternal: find or create slot for topic.
obs_subscribeSubscribe a handler function pointer to a topic. Handler signature: fn(data: …
obs_emit_iEmit an event to all subscribers of a topic. Calls each handler with the data…
obs_unsubscribe_allRemove all handlers for a topic.
obs_subscriber_countNumber of subscribers for a topic.

Details

obs_new

fn obs_new(max_topics: i64) -> &i64

Create an event bus.

obs_find_topic

fn obs_find_topic(bus: &i64, topic: i64) -> i64

Internal: find or create slot for topic.

obs_subscribe

fn obs_subscribe(bus: &i64, topic: i64, fn_ptr: i64)

Subscribe a handler function pointer to a topic. Handler signature: fn(data: i64) or fn(data: &i64)

obs_emit_i

fn obs_emit_i(bus: &i64, topic: i64, val: i64)

Emit an event to all subscribers of a topic. Calls each handler with the data argument.

obs_unsubscribe_all

fn obs_unsubscribe_all(bus: &i64, topic: i64)

Remove all handlers for a topic.

obs_subscriber_count

fn obs_subscriber_count(bus: &i64, topic: i64) -> i64

Number of subscribers for a topic.