-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocesses.erl
More file actions
59 lines (46 loc) · 1.42 KB
/
processes.erl
File metadata and controls
59 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
%%%-------------------------------------------------------------------
%%% @author Chris Duesing <chris.duesing@gmail.com>
%%% @copyright (C) 2010, Chris Duesing
%%% @doc
%%%
%%% @end
%%% Created : 18 Apr 2010 by Chris Duesing <chris.duesing@gmail.com>
%%%-------------------------------------------------------------------
-module(processes).
%% API
-export([start_simple/0, start_loop/0, run_loop/1, start_receiver/0, run_receiver/0]).
%%%===================================================================
%%% API
%%%===================================================================
%%--------------------------------------------------------------------
%% @doc
%% @spec
%% @end
%%--------------------------------------------------------------------
start_simple() ->
spawn(fun() -> io:format("Oh hai world!") end).
start_loop() ->
spawn(processes, run_loop, [5]).
run_loop(0) ->
io:format("done!~n");
run_loop(LoopsLeft) ->
io:format("loops left: ~w~n", [LoopsLeft]),
run_loop(LoopsLeft - 1).
start_receiver() ->
Pid = spawn(processes, run_receiver, []),
Pid ! "Joe",
Pid ! "Chris",
Pid ! 5,
ok.
run_receiver() ->
receive
"Chris" ->
io:format("Hey Chris!~n"),
run_receiver();
SomeoneElse when is_list(SomeoneElse) ->
io:format("Hey, ~s have you Seen Chris?~n", [SomeoneElse]),
run_receiver();
X ->
io:format("ack, ~w? seriously?~n", [X]),
error
end.