Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jan 18, 2024
1 parent 1e25a29 commit ce5dde6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/throttle/amoc_throttle_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ stop(Name) ->
telemetry_event(Name, Event) when Event =:= request; Event =:= execute ->
raise_event(Name, Event).

%% The purpose of this function is to ensure that there are no event duplicates if we are running in
%% a single (non-distributed) node, as the throttle process will already raise this event.
-spec raise_event_on_slave_node(name(), event()) -> ok.
raise_event_on_slave_node(Name, Event) ->
case amoc_cluster:master_node() =:= node() of
Expand Down
6 changes: 3 additions & 3 deletions src/throttle/amoc_throttle_process.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
interval = 0 :: amoc_throttle:interval(), %%ms
delay_between_executions = 0 :: non_neg_integer(), %%ms
tref :: timer:tref() | undefined,
schedule = [] :: [amoc_throttle_runner:runner()],
schedule_reversed = [] :: [amoc_throttle_runner:runner()]}).
schedule = [] :: [AmocThrottleRunnerProcess :: pid()],
schedule_reversed = [] :: [AmocThrottleRunnerProcess :: pid()]}).

-type state() :: #state{}.
%%------------------------------------------------------------------------------
Expand All @@ -53,7 +53,7 @@ start_link(Name, Interval, Rate) ->
stop(Pid) ->
gen_server:cast(Pid, stop_process).

-spec run(pid(), amoc_throttle_runner:runner()) -> ok.
-spec run(pid(), pid()) -> ok.
run(Pid, RunnerPid) ->
gen_server:cast(Pid, {schedule, RunnerPid}).

Expand Down
10 changes: 3 additions & 7 deletions src/throttle/amoc_throttle_runner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@
-export([async_runner/3]).

-type action() :: wait | {pid(), term()} | fun(() -> any()).
-type runner() :: pid().
-export_type([runner/0]).

-spec run(runner()) -> reference().
-spec run(pid()) -> term().
run(RunnerPid) ->
Ref = erlang:monitor(process, RunnerPid),
RunnerPid ! '$scheduled',
Ref.
RunnerPid ! '$scheduled'.

-spec throttle(amoc_throttle:name(), action()) -> ok | {error, any()}.
throttle(Name, Action) ->
Expand All @@ -30,7 +26,7 @@ throttle(Name, Action) ->
Error
end.

-spec maybe_wait(action(), runner()) -> ok.
-spec maybe_wait(action(), pid()) -> ok.
maybe_wait(wait, RunnerPid) ->
receive
{'EXIT', RunnerPid, Reason} ->
Expand Down

0 comments on commit ce5dde6

Please sign in to comment.