WIP: add Name arg to start_link()
This commit is contained in:
parent
2d3a29471d
commit
34c8c6490a
2 changed files with 9 additions and 8 deletions
|
@ -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}};
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue