1 |
|
%% This module contains the state of mongoose_domain_loader between calls. |
2 |
|
-module(mongoose_loader_state). |
3 |
|
-export([init/0, set/1, get/1, reset/0]). |
4 |
|
|
5 |
|
-define(TABLE, ?MODULE). |
6 |
|
|
7 |
|
%% Called by mongoose_domain_core |
8 |
|
%% The loader state lives till the core process lives. |
9 |
|
%% This means it survives service_domain_db restarts. |
10 |
|
init() -> |
11 |
359 |
ets:new(?TABLE, [set, named_table, public]). |
12 |
|
|
13 |
|
set(Val) -> |
14 |
591 |
ets:insert(?TABLE, {state, Val}). |
15 |
|
|
16 |
|
get(Def) -> |
17 |
1047 |
try |
18 |
1047 |
ets:lookup_element(?MODULE, state, 2) |
19 |
347 |
catch _:_:_ -> Def |
20 |
|
end. |
21 |
|
|
22 |
|
reset() -> |
23 |
12 |
ets:insert(?TABLE, {state, reset}). |