Skip to content

Commit

Permalink
Merge pull request #55 from campanja/otp-21
Browse files Browse the repository at this point in the history
Fix erl-21 erlang:get_stacktrace/0 in a clean fashion.
  • Loading branch information
Santiniis authored Oct 4, 2019
2 parents 5c50aed + d4448b4 commit b119bf3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ecrn_agent.erl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ until_next_milliseconds(State, Job) ->
{error, invalid_once_exception}
end.

%%-ifdef(OTP_VSN_21_AND_ABOVE).
-ifdef(OTP_RELEASE).
%% OTP 21 or higher
normalize_seconds(State, Seconds) ->
%% change for R21
%% get_stacktrace/0 not supported
try
Value = Seconds - current_time(State),
true = (Value >= 0)
catch
_C:_R:StackTrace ->
erlang:display(StackTrace),
throw(invalid_once_exception)
end.
-else.
normalize_seconds(State, Seconds) ->
case Seconds - current_time(State) of
Value when Value >= 0 ->
Expand All @@ -197,6 +212,7 @@ normalize_seconds(State, Seconds) ->
erlang:display(erlang:get_stacktrace()),
throw(invalid_once_exception)
end.
-endif.

%% @doc Calculates the duration in seconds until the next time
%% a job is to be run.
Expand Down

0 comments on commit b119bf3

Please sign in to comment.