_site/cover/pgmp_statem.COVER.html

1 %% Copyright (c) 2022 Peter Morgan <peter.james.morgan@gmail.com>
2 %%
3 %% Licensed under the Apache License, Version 2.0 (the "License");
4 %% you may not use this file except in compliance with the License.
5 %% You may obtain a copy of the License at
6 %%
7 %% http://www.apache.org/licenses/LICENSE-2.0
8 %%
9 %% Unless required by applicable law or agreed to in writing, software
10 %% distributed under the License is distributed on an "AS IS" BASIS,
11 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 %% See the License for the specific language governing permissions and
13 %% limitations under the License.
14
15
16 -module(pgmp_statem).
17
18
19 -export([cancel_generic_timeout/1]).
20 -export([generic_timeout/1]).
21 -export([nei/1]).
22 -export([send_request/1]).
23
24
25 -type request_id() :: gen_statem:request_id().
26 -type request_id_collection() :: gen_statem:request_id_collection().
27 -type server_ref() :: gen_statem:server_ref().
28
29 -type collection_req() :: #{server_ref := server_ref(),
30 request := any(),
31 label := any(),
32 requests := request_id_collection()}.
33
34 -type id_req() :: #{server_ref := server_ref(),
35 request := any()}.
36
37 -spec send_request(collection_req()) -> request_id_collection();
38 (id_req()) -> request_id().
39
40 send_request(#{server_ref := ServerRef,
41 request := Request,
42 label := Label,
43 requests := Requests}) ->
44 76011 gen_statem:send_request(ServerRef, Request, Label, Requests);
45
46 send_request(#{requests := _} = Arg) ->
47
:-(
error(badarg, [Arg]);
48
49 send_request(#{server_ref := ServerRef, request := Request}) ->
50 11860 gen_statem:send_request(ServerRef, Request).
51
52
53 -spec nei(any()) -> {next_event, internal, any()}.
54
55 nei(Event) ->
56 1266173 {next_event, internal, Event}.
57
58
59 generic_timeout(Name) ->
60 370 ?FUNCTION_NAME(Name, pgmp_config:timeout(Name)).
61
62 -type timeout_type() :: {{timeout, term()}, timeout(), term()}.
63
64
65 -spec cancel_generic_timeout(term()) -> timeout_type().
66
67 cancel_generic_timeout(Name) ->
68 365 generic_timeout(Name, infinity).
69
70
71 -spec generic_timeout(term(), timeout()) -> timeout_type().
72
73 generic_timeout(Name, Timeout) ->
74 735 {{timeout, Name}, Timeout, Name}.
Line Hits Source