Grouping unused gen_server callbacks.
[cellular-automata.git] / 001 / src / life_cell.erl
index 2ebdf7b..9f7b171 100644 (file)
@@ -38,6 +38,16 @@ start_link({_, Name, _}=Datum) ->
     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
 %% ============================================================================
@@ -55,18 +65,6 @@ init([{CellID, Name, NeighborNames}]) ->
     {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
@@ -75,11 +73,11 @@ handle_cast({next_gen, GenID},
           ,early_msgs=EarlyMsgs
           }=State) ->
 
-    ok = cast_all(Neighbors, {state_broadcast, GenID, CellState}),
+    ok = 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 = cast_all2one(Name, EarlyMsgs),
 
     NewState = State#state{replies_pending=NumNeighbors
                           ,gen_id=GenID
@@ -139,26 +137,22 @@ handle_cast(_Msg, State) ->
     {noreply, State}.
 
 
-handle_info(_Msg, State) ->
-    {noreply, State}.
-
-
 %% ============================================================================
 %% Internal
 %% ============================================================================
 
-% Cast different messages to a single destination
-cast_to(_, []) -> ok;
-cast_to(Server, [Msg | Msgs]) ->
+% Cast all messages to one destination
+cast_all2one(_, []) -> ok;
+cast_all2one(Server, [Msg | Msgs]) ->
     ok = gen_server:cast(Server, Msg),
-    cast_to(Server, Msgs).
+    cast_all2one(Server, Msgs).
 
 
-% Cast the same message to multiple destinations
-cast_all([], _) -> ok;
-cast_all([Server | Servers], Msg) ->
+% Cast one message to all destinations
+cast_one2all([], _) -> ok;
+cast_one2all([Server | Servers], Msg) ->
     ok = gen_server:cast(Server, Msg),
-    cast_all(Servers, Msg).
+    cast_one2all(Servers, Msg).
 
 
 new_state(1, LiveNeighbors) when LiveNeighbors  <  2 -> 0;
This page took 0.027167 seconds and 4 git commands to generate.