Skip to content

Commit

Permalink
Replace stacktrace dependency with macro
Browse files Browse the repository at this point in the history
  • Loading branch information
David Leach committed Aug 13, 2018
1 parent 45386b0 commit 77caed3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 1 addition & 6 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{erl_opts, [
debug_info,
{platform_define, "^R", pre17},
{parse_transform, stacktrace_transform}
]}.

{deps, [
{stacktrace_compat, "1.0.0"}
{platform_define, "^R", pre17}
]}.

{eunit_opts, [verbose]}.
Expand Down
13 changes: 10 additions & 3 deletions src/poolboy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
{global, GlobalName :: any()} |
{via, Module :: atom(), ViaName :: any()}.

-ifdef(OTP_RELEASE). %% this implies 21 or higher
-define(EXCEPTION(Class, Reason, Stacktrace), Class:Reason:Stacktrace).
-define(GET_STACK(Stacktrace), Stacktrace).
-else.
-define(EXCEPTION(Class, Reason, _), Class:Reason).
-define(GET_STACK(_), erlang:get_stacktrace()).
-endif.

% Copied from gen:start_ret/0
-type start_ret() :: {'ok', pid()} | 'ignore' | {'error', term()}.

Expand Down Expand Up @@ -84,10 +92,9 @@ checkout(Pool, Block, Timeout) ->
try
gen_server:call(Pool, {checkout, CRef, Block}, Timeout)
catch
Class:Reason ->
Stack = erlang:get_stacktrace(),
?EXCEPTION(Class, Reason, Stacktrace) ->
gen_server:cast(Pool, {cancel_waiting, CRef}),
erlang:raise(Class, Reason, Stack)
erlang:raise(Class, Reason, ?GET_STACK(Stacktrace))
end.

-spec checkin(Pool :: pool(), Worker :: pid()) -> ok.
Expand Down

0 comments on commit 77caed3

Please sign in to comment.