% Compared with module mserver2.erl -module(genservermath). -export([start/0,compute_factorial/2]). % engine of the server % request: to compute the factorial engine(Count, {factorial,N}) -> Result = math_examples:factorial(N), {Result, Count+1} ; % request: to ask for the state of the server engine(Count, get_count) -> {Count, Count} ; engine(Count, _) -> {i_dont_get_it, Count}. start() -> genserver:start(server, 0, fun engine/2). compute_factorial(Pid, N) -> genserver:request(Pid, {factorial, N}).