Skip to content

Add command/1 type and export #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/ra_machine.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@

-type builtin_command() :: {down, pid(), term()} |
{nodeup | nodedown, node()} |
{machine_version, From :: version(), To :: version()} |
{timeout, term()}.
%% These commands may be passed to the {@link apply/2} function in reaction
%% to monitor effects
Expand Down Expand Up @@ -196,7 +197,7 @@
%% used {@link ra:process_command/2} or
%% {@link ra:process_command/3}

-type command() :: user_command() | builtin_command().
-type command(UserCommand) :: UserCommand | builtin_command().

-type command_meta_data() :: #{system_time := integer(),
index := ra_index(),
Expand All @@ -213,6 +214,7 @@
effects/0,
reply/0,
builtin_command/0,
command/1,
command_meta_data/0]).

-optional_callbacks([tick/2,
Expand All @@ -239,7 +241,7 @@

-callback init(Conf :: machine_init_args()) -> state().

-callback 'apply'(command_meta_data(), command(), State) ->
-callback 'apply'(command_meta_data(), command(term()), State) ->
{State, reply(), effects() | effect()} | {State, reply()} when State :: term().

%% Optional callbacks
Expand Down Expand Up @@ -302,7 +304,7 @@ init({machine, _, Args} = Machine, Name, Version) ->
Mod:init(Args#{name => Name,
machine_version => Version}).

-spec apply(module(), command_meta_data(), command(), State) ->
-spec apply(module(), command_meta_data(), command(term()), State) ->
{State, reply(), effects()} | {State, reply()}.
apply(Mod, Metadata, Cmd, State) ->
Mod:apply(Metadata, Cmd, State).
Expand Down
2 changes: 1 addition & 1 deletion test/ra_fifo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{discard, MsgIds :: [msg_id()], Customer :: customer_id()} |
purge.

-type command() :: protocol() | ra_machine:builtin_command().
-type command() :: ra_machine:command(protocol()).
%% all the command types supported by ra fifo

-type client_msg() :: delivery().
Expand Down