simple proc_lib test example

jose joseerlang@REDACTED
Wed Jul 26 12:36:42 CEST 2006


jm escribió:
> Having some problems with the following program is simplified example 
> based on something I'm trying to write,
>
> -module(test_proc).
>
> -export([go/0]).
>
> go() ->
>   proc_lib:start_link(?MODULE, simple, [], infinity).
>
> simple() ->
>   proc_lib:init_ack({ok, self()}),
>   await().
>
> await() ->
>   receive
>     after 1000 ->
>       exit({ok, timeout})
>    end.
>
>
> $ erlc test_proc.erl
> ./test_proc.erl:21: Warning: function await/0 is unused
> ./test_proc.erl:21: Warning: function simple/0 is unused
>
> It doesn't look good at this stage. Why does it say unused? await/0 is 
> call from simple and simple/0 from proc_lib:start_link. I can 
> understand the latter though as it's call from proc_lib:start_link as 
> a parameter. Ignoring this and continuing....
>
> $ erl
> Erlang (BEAM) emulator version 5.4.8 [source] [hipe]
>
> Eshell V5.4.8  (abort with ^G)
> 1> test_proc:go().
> ** exited: {undef,[{test_proc,simple,[]},{proc_lib,init_p,5}]} **
> 2>
>
> and this where it hits a wall. Most likely it a simple beginner's 
> error. Anyone to point out the glaringly obvious to me?
>
> Also, are the any good examples of code floating around?
>
> Jeff.
>
>
-module(test_proc).

%% ;-)
-export([go/0,simple/0]).

go() ->
  proc_lib:start_link(?MODULE, simple, [], infinity).

simple() ->
  proc_lib:init_ack({ok, self()}),
  await().

await() ->
  receive
    after 1000 ->
      exit({ok, timeout})
   end.
jgarcia@REDACTED:~$ erl
Erlang (BEAM) emulator version 5.4.9 [source] [threads:0]

Eshell V5.4.9  (abort with ^G)
1> c(test_proc).
{ok,test_proc}
2> test_proc:go().
{ok,<0.38.0>}
** exited: {ok,timeout} **
3>
3> halt().






More information about the erlang-questions mailing list