Skip to content

Commit

Permalink
Moving through chapter 8
Browse files Browse the repository at this point in the history
  • Loading branch information
lucashungaro committed Mar 2, 2009
1 parent ddc61e6 commit f8abe61
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions erlang/chat/#message_router.erl#
@@ -0,0 +1,5 @@
-module(${1:$(file-name-nondirectory
(file-name-sans-extension (buffer-file-name)))}).
$0

mod
Empty file added erlang/chat/message_router.erl
Empty file.
19 changes: 19 additions & 0 deletions erlang/ctemplate.erl
@@ -0,0 +1,19 @@
-module(ctemplate).
-compile(export_all).

start() ->
spawn(fun() -> loop([]) end).

rpc(Pid, Request) ->
Pid ! {self(), Request},
receive
{Pid, Response} ->
Response
end.

loop(X) ->
receive
Any ->
io:format("Received:~p~n",[Any]),
loop(X)
end.
22 changes: 22 additions & 0 deletions erlang/misc.erl
Expand Up @@ -295,3 +295,25 @@ priority_receive() ->
end
end.

% Registered processes
% register(AnAtom, Pid)
% Register the process Pid with the name AnAtom. The registration
% fails if AnAtom has already been used to register a process.

% unregister(AnAtom)
% Remove any registrations associated with AnAtom.
% Note: If a registered process dies it will be automatically unregis-tered.

% whereis(AnAtom) -> Pid | undefined
% Find out whether AnAtom is registered. Return the process identifier
% Pid, or retur n the atom undefined if no process is associated with AnAtom.

% registered() -> [AnAtom::atom()]
% Retur n a list of all registered processes in the system.

Pid = spawn(fun area_server0:loop/0).

register(area, Pid).

area ! {rectangle, 4, 5}.

11 changes: 11 additions & 0 deletions erlang/test.erl
@@ -0,0 +1,11 @@
-module(test).
-compile(export_all).

start(Atom, Fun) ->
register(Atom, spawn(fun loop/0)).

loop() ->
receive
_ ->
void
end.

0 comments on commit f8abe61

Please sign in to comment.