Search documentation of macula

# macula_pubsub_registry (macula v0.44.2)

View Source

Local subscription registry for pub/sub. Maps topic patterns to local subscribers (callback PIDs).

# Summary

## Types

registry/0
subscription/0

## Functions

get_subscription(_, SubscriberId, Pattern)

Get specific subscription.

list_patterns(_)

List all unique patterns.

match(_, Topic)

Find subscriptions matching a topic.

new()

Create new empty registry.

size(_)

Get number of subscriptions.

subscribe(Registry, SubscriberId, Pattern, Callback)

Subscribe to a pattern. If subscription already exists (same subscriber_id + pattern), updates callback.

unsubscribe(Registry, SubscriberId, Pattern)

Unsubscribe from a pattern.

# Types

# registry/0

    -type registry() ::
              #{subscriptions := [subscription()], pattern_index := #{binary() => [subscription()]}}.

# subscription/0

    -type subscription() :: #{subscriber_id := binary(), pattern := binary(), callback := pid()}.

# Functions

# get_subscription(_, SubscriberId, Pattern)

    -spec get_subscription(registry(), binary(), binary()) -> {ok, subscription()} | not_found.

Get specific subscription.

# list_patterns(_)

    -spec list_patterns(registry()) -> [binary()].

List all unique patterns.

# match(_, Topic)

    -spec match(registry(), binary()) -> [subscription()].

Find subscriptions matching a topic.

# new()

    -spec new() -> registry().

Create new empty registry.

# size(_)

    -spec size(registry()) -> non_neg_integer().

Get number of subscriptions.

# subscribe(Registry, SubscriberId, Pattern, Callback)

    -spec subscribe(registry(), binary(), binary(), pid()) -> registry().

Subscribe to a pattern. If subscription already exists (same subscriber_id + pattern), updates callback.

# unsubscribe(Registry, SubscriberId, Pattern)

    -spec unsubscribe(registry(), binary(), binary()) -> registry().

Unsubscribe from a pattern.