diff --git a/prototype/poc-machi/src/machi_flu0.erl b/prototype/poc-machi/src/machi_flu0.erl index 4e0ccc4..463d3c9 100644 --- a/prototype/poc-machi/src/machi_flu0.erl +++ b/prototype/poc-machi/src/machi_flu0.erl @@ -2,7 +2,7 @@ -behaviour(gen_server). --export([start_link/0, stop/1, +-export([start_link/1, stop/1, write/2, get/1, trim/1]). -ifdef(TEST). -compile(export_all). @@ -27,11 +27,12 @@ -type register() :: 'unwritten' | binary() | 'trimmed'. -record(state, { + name :: list(), register = 'unwritten' :: register() }). -start_link() -> - gen_server:start_link(?MODULE, [], []). +start_link(Name) when is_list(Name) -> + gen_server:start_link(?MODULE, [Name], []). stop(Pid) -> gen_server:call(Pid, stop, infinity). @@ -47,8 +48,8 @@ trim(Pid) -> %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% %%%% -init([]) -> - {ok, #state{}}. +init([Name]) -> + {ok, #state{name=Name}}. handle_call({write, Bin}, _From, #state{register=unwritten} = S) -> {reply, ok, S#state{register=Bin}}; diff --git a/prototype/poc-machi/test/machi_flu0_test.erl b/prototype/poc-machi/test/machi_flu0_test.erl index ec5bc8b..2691a3c 100644 --- a/prototype/poc-machi/test/machi_flu0_test.erl +++ b/prototype/poc-machi/test/machi_flu0_test.erl @@ -13,13 +13,13 @@ concuerror1_test() -> ok. concuerror2_test() -> - {ok, F} = machi_flu0:start_link(), + {ok, F} = machi_flu0:start_link("one"), ok = machi_flu0:stop(F), ok. concuerror3_test() -> Me = self(), - Fun = fun() -> {ok, F1} = machi_flu0:start_link(), + Fun = fun() -> {ok, F1} = machi_flu0:start_link("one"), ok = machi_flu0:stop(F1), Me ! done end, @@ -30,7 +30,7 @@ concuerror3_test() -> ok. concuerror4_test() -> - {ok, F1} = machi_flu0:start_link(), + {ok, F1} = machi_flu0:start_link("one"), Val = <<"val!">>, ok = machi_flu0:write(F1, Val), Me = self(),