-module(mix_worker). -behaviour(gen_server). %% API -export([start_link/0]). -export([add/2]). -export([double/1]). -record(state, {}). -define(SERVER, MODULE). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). start_link() -> gen_server:start_link({local, SERVER}, MODULE, [], []). add(A, B) -> gen_server:call(MODULE, {add, A, B}). double(A) -> gen_server:call(MODULE, {double, A}). init([]) -> {ok, #state{}}. handle_call({add, X, Y}, _From, State) -> {reply, X+Y, State}; handle_call({double, X}, _From, State) -> {reply, X*2, State}; handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. |