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 |
143 |
ets:new(?TABLE, [set, named_table, public]). |
12 |
|
|
13 |
|
set(Val) -> |
14 |
352 |
ets:insert(?TABLE, {state, Val}). |
15 |
|
|
16 |
|
get(Def) -> |
17 |
558 |
try |
18 |
558 |
ets:lookup_element(?MODULE, state, 2) |
19 |
143 |
catch _:_:_ -> Def |
20 |
|
end. |
21 |
|
|
22 |
|
reset() -> |
23 |
1 |
ets:insert(?TABLE, {state, reset}). |