mailio_events (mailio v0.2.0)

Live event registry and fan-out.

A single gen_server holds subscriptions in an ETS table and dispatches normalized domain events to subscriber processes. Dispatch uses plain message sends and never blocks on a slow subscriber; delivery is best-effort. Subscribers needing at-least-once semantics resume from the seq carried on every envelope via mailio_changes:since/3 in the store.

Subscribers are monitored and their subscriptions are removed on exit.

Summary

Functions

Dispatch an envelope to all matching subscribers. Returns the number of subscribers it was delivered to.

Subscribe with a topic filter map: #{account => Id |_', types => [email|mailbox|thread|...] | all}'. Events arrive as {mailio_event, SubRef, Envelope}.

Functions

dispatch(Envelope)

-spec dispatch(map()) -> non_neg_integer().

Dispatch an envelope to all matching subscribers. Returns the number of subscribers it was delivered to.

handle_call(Req, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

subscribe(Topic)

-spec subscribe(map()) -> {ok, reference()}.

Subscribe with a topic filter map: #{account => Id |_', types => [email|mailbox|thread|...] | all}'. Events arrive as {mailio_event, SubRef, Envelope}.

subscribe(Topic, Pid)

-spec subscribe(map(), pid()) -> {ok, reference()}.

terminate(Reason, State)

unsubscribe(Ref)

-spec unsubscribe(reference()) -> ok.