macula_publisher behaviour (macula v10.1.1)
View SourceBehaviour for supervised content publishers.
macula:publish/4 is a plain blocking call — no addressable pid to cancel it from outside. This is the missing supervised counterpart to macula_subscriber: every other primitive pair already has one on each side (macula_request/macula_response for RPC, macula_streamer/macula_stream_sink for streaming RPC, macula_feeder/macula_download for content sharing) — pubsub had only the consumer half. start_link/5,6 returns immediately with a pid, runs macula:publish/4 in a linked worker, delivers the outcome to Module:handle_published/2, and publishes pubsub.publish_started_v1 / pubsub.publish_completed_v1 mesh facts around the publish — including outcome => cancelled if the publisher is stopped before the publish resolves.
Example
-module(status_publisher).
-behaviour(macula_publisher).
-export([init/1, handle_published/2]).
init(Parent) -> {ok, Parent}.
handle_published(Result, Parent) ->
Parent ! {published, Result},
{stop, normal, Parent}. {ok, Pid} = macula_publisher:start_link(status_publisher, Pool, Realm,
Topic, Payload, self()).
Summary
Functions
Cancel an in-flight publish. Publishes pubsub.publish_completed_v1 with outcome => cancelled if the publish had not resolved yet.
Start a publisher. Publishes Payload on Topic via Pool.
As start_link/5, with Args passed to Module:init/1.
Callbacks
Functions
-spec cancel(pid()) -> ok.
Cancel an in-flight publish. Publishes pubsub.publish_completed_v1 with outcome => cancelled if the publish had not resolved yet.
-spec start_link(module(), macula:pool(), macula:realm(), macula:topic(), term()) -> {ok, pid()} | {error, term()}.
Start a publisher. Publishes Payload on Topic via Pool.
-spec start_link(module(), macula:pool(), macula:realm(), macula:topic(), term(), term()) -> {ok, pid()} | {error, term()}.
As start_link/5, with Args passed to Module:init/1.