-handle_cast({request_state, Requester}, State) ->
- ok = gen_server:cast(Requester, {response_state, State#state.cell_state}),
- {noreply, State};
+ % Put stashed messages back in the mailbox,
+ % now that we're ready to handle them
+ ok = life_lib:cast_all2one(Name, EarlyMsgs),
+
+ NewState = State#state{replies_pending=NumNeighbors
+ ,gen_id=GenID
+ ,early_msgs=[]
+ },
+
+ {noreply, NewState};
+
+
+%% If we receive 'state_broadcast' before we receive 'next_gen',
+%% stash it until we do.
+%%
+%% Took me a while to realize this, but sometimes it is possible. The more
+%% there're cells, the more likely this is to happen.
+%%
+handle_cast({state_broadcast, ReceivedGenID, _NeighborState}=Msg,
+ #state{gen_id=GenID
+ ,early_msgs=EarlyMsgs
+ }=State) when GenID =/= ReceivedGenID ->
+
+ {noreply, State#state{early_msgs=[Msg|EarlyMsgs]}};