• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

emqx / emqx / 12580002997

02 Jan 2025 09:05AM UTC coverage: 82.034%. First build
12580002997

Pull #14475

github

web-flow
Merge 2f431ed61 into d5a56c20b
Pull Request #14475: refactor(limiter): refactor and simplify the limiter

165 of 233 new or added lines in 20 files covered. (70.82%)

56317 of 68651 relevant lines covered (82.03%)

15172.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/apps/emqx/src/emqx_limiter/src/emqx_limiter_shared.erl
1
%%--------------------------------------------------------------------
2
%% Copyright (c) 2021-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
3
%%
4
%% Licensed under the Apache License, Version 2.0 (the "License");
5
%% you may not use this file except in compliance with the License.
6
%% You may obtain a copy of the License at
7
%%
8
%%     http://www.apache.org/licenses/LICENSE-2.0
9
%%
10
%% Unless required by applicable law or agreed to in writing, software
11
%% distributed under the License is distributed on an "AS IS" BASIS,
12
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
%% See the License for the specific language governing permissions and
14
%% limitations under the License.
15
%%--------------------------------------------------------------------
16

17
-module(emqx_limiter_shared).
18

19
-behaviour(emqx_limiter).
20

21
%% API
22
-export([create/1, check/2, restore/2]).
23
-export_type([limiter/0]).
24

25
-type bucket() :: emqx_limiter_bucket_ref:bucket_ref().
26

27
-type limiter() :: #{
28
    module := ?MODULE,
29
    bucket := bucket(),
30
    %% allow to add other keys
31
    atom => any()
32
}.
33

34
%%--------------------------------------------------------------------
35
%%  API
36
%%--------------------------------------------------------------------
37

38
-spec create(bucket()) -> limiter().
39
create(Bucket) ->
40
    #{
264✔
41
        module => ?MODULE,
42
        bucket => Bucket
43
    }.
44

45
check(Need, #{bucket := Bucket} = Limiter) ->
46
    {emqx_limiter_bucket_ref:check(Need, Bucket), Limiter}.
155✔
47

48
restore(Consumed, #{bucket := Bucket} = Limiter) ->
NEW
49
    emqx_limiter_bucket_ref:restore(Consumed, Bucket),
×
NEW
50
    Limiter.
×
51

52
%%--------------------------------------------------------------------
53
%%  Internal functions
54
%%--------------------------------------------------------------------
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc