macula_download behaviour (macula v9.3.1)

View Source

Behaviour for supervised content downloads (the get/fetch side).

get_content/2 is a plain blocking call — no addressable pid to cancel it from outside. This is the consumer-side counterpart to macula_feeder: start_link/4,5 returns immediately with a pid, runs macula:get_content/2 in a linked worker, delivers the outcome to Module:handle_downloaded/2, and publishes sharing.get_started_v1 / sharing.get_completed_v1 mesh facts around the transfer — including outcome => cancelled if the download is cancelled before the get resolves.

This is content sharing, not general-purpose RPC streaming — see macula_streamer / macula_stream_sink for that (streaming.* facts belong to that pair).

Example

   -module(doc_download).
   -behaviour(macula_download).
   -export([init/1, handle_downloaded/2]).
  
   init(Parent) -> {ok, Parent}.
  
   handle_downloaded(Result, Parent) ->
       Parent ! {downloaded, Result},
       {stop, normal, Parent}.
   {ok, Pid} = macula_download:start_link(doc_download, Pool, Realm,
       Mcid, self()).

Summary

Functions

Cancel an in-flight download. Publishes sharing.get_completed_v1 with outcome => cancelled if the get had not resolved yet.

Start a download. Fetches Mcid via Pool.

As start_link/4, with Args passed to Module:init/1.

Callbacks

handle_downloaded/2

-callback handle_downloaded(Result :: {ok, binary()} | {error, term()}, State :: term()) ->
                               {noreply, NewState :: term()} | {stop, Reason :: term(), NewState :: term()}.

init/1

-callback init(Args :: term()) -> {ok, State :: term()} | {stop, Reason :: term()}.

Functions

cancel(Pid)

-spec cancel(pid()) -> ok.

Cancel an in-flight download. Publishes sharing.get_completed_v1 with outcome => cancelled if the get had not resolved yet.

start_link(Module, Pool, Realm, Mcid)

-spec start_link(module(), macula:pool(), macula:realm(), macula:mcid()) ->
                    {ok, pid()} | {error, term()}.

Start a download. Fetches Mcid via Pool.

start_link(Module, Pool, Realm, Mcid, Args)

-spec start_link(module(), macula:pool(), macula:realm(), macula:mcid(), term()) ->
                    {ok, pid()} | {error, term()}.

As start_link/4, with Args passed to Module:init/1.