Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % version 2
- -module(code_change_test).
- -behaviour(gen_server).
- -export([start/0, stop/0]).
- -export([state/0]).
- -export([
- init/1,
- handle_call/3, handle_cast/2, handle_info/2,
- terminate/2, code_change/3
- ]).
- start() -> gen_server:start({local, ?MODULE}, ?MODULE, [], []).
- stop() -> gen_server:cast(?MODULE, stop).
- state() -> gen_server:call(?MODULE, state).
- init(_Args) ->
- {ok, {ver2, [foo, bar]}}.
- handle_call(state, _From, {ver2, Args}=State) ->
- io:fwrite("State=~p~n", [Args]),
- {reply, Args, State};
- handle_call(_Message, _From, State) ->
- {reply, ok, State}.
- handle_cast(stop, State) ->
- {stop, normal, State};
- handle_cast(_Message, State) ->
- {noreply, State}.
- handle_info(_Info, State) -> {noreply, State}.
- terminate(normal, _State) -> ok;
- terminate(_, _) -> ok.
- code_change(OldVsn, State, Extra) ->
- io:fwrite(
- lists:foldl(
- fun (Name, Format) -> Format ++ Name ++ "=~p~n" end,
- "code_change~n", ["OldVsn", "State", "Extra"]
- ),
- [OldVsn, State, Extra]
- ),
- {ok, {ver2, [foo, bar]}}.
Add Comment
Please, Sign In to add comment