Skip to content

Commit 373b6b5

Browse files
committed
Make spillway OTP 27 compatible
1 parent 06fbed3 commit 373b6b5

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/spillway_srv.erl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
-record(counter, {name, value = 0 :: non_neg_integer()}).
3636

37+
-elvis([{elvis_style, dont_repeat_yourself, disable}]).
38+
3739
%%%===================================================================
3840
%%% External functions
3941
%%%===================================================================
@@ -68,24 +70,27 @@ enter(Name, Size, Limit) when Size > 0 ->
6870

6971
%% Attempt to decrement the named counter, with a lower limit of 0. Return the new value.
7072
%% The counter must already exist.
73+
-if(?OTP_RELEASE =< 25).
74+
7175
-spec leave(term(), non_neg_integer()) -> non_neg_integer().
7276
leave(Name, Size) ->
73-
Counter =
74-
case ets:update_counter(?TID, Name, {#counter.value, -Size, 0, 0}) of
75-
[] ->
76-
0;
77-
[Result | _] ->
78-
Result;
79-
Result ->
80-
Result
81-
end,
82-
case Counter >= 0 of
83-
true ->
84-
Counter;
85-
false ->
86-
0
77+
ets:update_counter(?TID, Name, {#counter.value, -Size, 0, 0}).
78+
79+
- else .
80+
81+
-spec leave(term(), non_neg_integer()) -> non_neg_integer().
82+
leave(Name, Size) ->
83+
case ets:update_counter(?TID, Name, {#counter.value, -Size, 0, 0}) of
84+
[] ->
85+
0;
86+
[Result | _] ->
87+
Result;
88+
Result ->
89+
Result
8790
end.
8891

92+
-endif.
93+
8994
%% Return the current counter value.
9095
-spec cur(term()) -> non_neg_integer().
9196
cur(Name) ->

0 commit comments

Comments
 (0)