home
/
code
/
cellular-automata.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
API tweeks, bangs to casts.
[cellular-automata.git]
/
001
/
src
/
cell.erl
diff --git
a/001/src/cell.erl
b/001/src/cell.erl
index
6090fa0
..
227f673
100644
(file)
--- a/
001/src/cell.erl
+++ b/
001/src/cell.erl
@@
-64,28
+64,21
@@
handle_call(_Msg, _From, State) ->
{reply, ok, State}.
{reply, ok, State}.
-handle_cast(_Msg, State) ->
- {noreply, State}.
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-handle_info(tick,
+handle_cast(tick,
#state{name=Name
,neighbors=Neighbors
,num_neighbors=NumNeighbors
}=State) ->
#state{name=Name
,neighbors=Neighbors
,num_neighbors=NumNeighbors
}=State) ->
-
- ok = send_all(Neighbors, {request_state, Name}),
+ ok = cast_all(Neighbors, {request_state, Name}),
{noreply, State#state{replies_pending=NumNeighbors}};
{noreply, State#state{replies_pending=NumNeighbors}};
-handle_
info
({request_state, Requester}, State) ->
-
Requester ! {response_state, State#state.cell_state}
,
+handle_
cast
({request_state, Requester}, State) ->
+
ok = gen_server:cast(Requester, {response_state, State#state.cell_state})
,
{noreply, State};
{noreply, State};
-handle_
info
({response_state, NeighborState},
+handle_
cast
({response_state, NeighborState},
#state{id=ID
,replies_pending=Pending
,cell_state=CellState
#state{id=ID
,replies_pending=Pending
,cell_state=CellState
@@
-102,17
+95,20
@@
handle_info({response_state, NeighborState},
case NewPending of
0 ->
NewCellState = new_state(CellState, NewLiveNeighbors),
case NewPending of
0 ->
NewCellState = new_state(CellState, NewLiveNeighbors),
- ok = time:
cast({tock, {ID, NewCellState}}
),
+ ok = time:
tock(ID, NewCellState
),
{noreply, NewState#state{live_neighbors=0
,cell_state=NewCellState
{noreply, NewState#state{live_neighbors=0
,cell_state=NewCellState
- }};
+ }
+ };
_N ->
{noreply, NewState}
end;
_N ->
{noreply, NewState}
end;
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
handle_info(_Msg, State) ->
handle_info(_Msg, State) ->
@@
-123,10
+119,10
@@
handle_info(_Msg, State) ->
%% Internal
%% ============================================================================
%% Internal
%% ============================================================================
-
send
_all([], _) -> ok;
-
send_all([PID | PID
s], Msg) ->
-
PID ! Msg
,
-
send_all(PID
s, Msg).
+
cast
_all([], _) -> ok;
+
cast_all([Server | Server
s], Msg) ->
+
ok = gen_server:cast(Server, Msg)
,
+
cast_all(Server
s, Msg).
new_state(1, LiveNeighbors) when LiveNeighbors < 2 -> 0;
new_state(1, LiveNeighbors) when LiveNeighbors < 2 -> 0;
This page took
0.029093 seconds
and
4
git commands to generate.