mcl_core_simple_handler (mcl_core v1.0.0)

View Source

Bridges macula's native {Module, Function} single-call handler convention into macula_response's per-request init/1 + handle_request/2 contract, for a handler that needs no per-request state — the common case for a service migrating a capability from bare macula:advertise/5 onto mcl_core_capabilities:register/1 (see CHANGELOG 0.24.0).

Without this, every migrating service would hand-write its own init/1/handle_request/2 pair per capability just to keep calling the one-arity function it already had.

Wire-compatible with the bare {Module, Function} path it replaces: macula_station_link's native dispatch strips an {ok, _} wrapper from a successful reply before it hits the wire (normalise_reply/1); macula_response's own outcome/1 re-wraps whatever handle_request/2 replies with in {ok, _} one layer up. This module strips {ok, _} itself so the two layers don't compose into a double-wrapped payload — a migrated capability's wire response is byte-for-byte the same as before migration.

Summary

Functions

macula_response's per-request handle_request/2 callback. Calls Module:Function(Payload) and translates its result into the {reply, _, _} | {error, _, _} shape macula_response expects, unwrapping an {ok, Value} result to just Value — see this module's own doc for why that unwrap has to happen here.

macula_response's per-request init/1 callback. State is just the {Module, Function} pair this handler will dispatch to — there is nothing else to initialize for a stateless handler. {Module, Function, Args} calls Module:Function(Payload, Args...): the handler of a capability that must know which hosted service it answers for, such as info on a node hosting several (mcl-om#8).

Types

state/0

-type state() :: {module(), atom()} | {module(), atom(), [term()]}.

Functions

handle_request(Payload, State)

-spec handle_request(term(), state()) -> {reply, term(), state()} | {error, term(), state()}.

macula_response's per-request handle_request/2 callback. Calls Module:Function(Payload) and translates its result into the {reply, _, _} | {error, _, _} shape macula_response expects, unwrapping an {ok, Value} result to just Value — see this module's own doc for why that unwrap has to happen here.

init(State)

-spec init(state()) -> {ok, state()}.

macula_response's per-request init/1 callback. State is just the {Module, Function} pair this handler will dispatch to — there is nothing else to initialize for a stateless handler. {Module, Function, Args} calls Module:Function(Payload, Args...): the handler of a capability that must know which hosted service it answers for, such as info on a node hosting several (mcl-om#8).