gen_server:start_link(ServerName, ?MODULE, Args, Opts).
+%% ============================================================================
+%% Callbacks (unused)
+%% ============================================================================
+
+handle_call(_Msg, _From, State) -> {reply, ok, State}.
+handle_info(_Msg, State) -> {noreply, State}.
+code_change(_Old, State, _Other) -> {ok, State}.
+terminate(_Reason, State) -> {ok, State}.
+
+
%% ============================================================================
%% Callbacks
%% ============================================================================
{ok, State}.
-terminate(_Reason, State) ->
- {ok, State}.
-
-
-code_change(_Old, State, _Other) ->
- {ok, State}.
-
-
-handle_call(_Msg, _From, State) ->
- {reply, ok, State}.
-
-
handle_cast({next_gen, GenID},
#state{name=Name
,cell_state=CellState
,early_msgs=EarlyMsgs
}=State) ->
- ok = cast_all(Neighbors, {state_broadcast, GenID, CellState}),
+ ok = life_lib:cast_one2all(Neighbors, {state_broadcast, GenID, CellState}),
% Put stashed messages back in the mailbox,
% now that we're ready to handle them
- ok = cast_to(Name, EarlyMsgs),
+ ok = life_lib:cast_all2one(Name, EarlyMsgs),
NewState = State#state{replies_pending=NumNeighbors
,gen_id=GenID
{noreply, State}.
-handle_info(_Msg, State) ->
- {noreply, State}.
-
-
%% ============================================================================
%% Internal
%% ============================================================================
-% Cast different messages to a single destination
-cast_to(_, []) -> ok;
-cast_to(Server, [Msg | Msgs]) ->
- ok = gen_server:cast(Server, Msg),
- cast_to(Server, Msgs).
-
-
-% Cast the same message to multiple destinations
-cast_all([], _) -> ok;
-cast_all([Server | Servers], Msg) ->
- ok = gen_server:cast(Server, Msg),
- cast_all(Servers, Msg).
-
-
new_state(1, LiveNeighbors) when LiveNeighbors < 2 -> 0;
new_state(1, LiveNeighbors) when LiveNeighbors < 4 -> 1;
new_state(1, LiveNeighbors) when LiveNeighbors > 3 -> 0;