[erlang-questions] calling timer_interval from module

Zoltan Lajos Kis <>
Fri Apr 30 20:38:01 CEST 2010


On 4/30/2010 7:57 PM, Wes James wrote:
> If I have:
>
> -module('gpc').
>
> -export([start/0]).
>
> start() ->
> 	%{ok,R}=
> 	timer:apply_interval(3000, gpc, getc, []).
>
> getc() ->  "yep".
>
> when I run:
>
> gpc:start().
>
> I get the error:
>
> =ERROR REPORT==== 30-Apr-2010::11:39:15 ===
> Error in process<0.70.0>  with exit value: {undef,[{gpc,getc,[]}]}
>
> If I change -export to:
>
> -export([start/0, getc/0]).
>
> If I run:
>
> {ok,R}=timer:apply_interval(3000, gpc, getc, []).
>
> I get
>
> {ok,{interval,#Ref<0.0.0.461>}}
>
> but nothing ever happens.
>
> If I do the same thing with:
>
>
> -module(tst).
>
> -export([tst_fun/0]).
>
> tst_fun() ->
> 	io:format("~n~w~n", [erlang:localtime()]).
>
>
> tst:tst_fun().
>
>
> It works??
>
> Any idea why the first doesn't work?
>
> The difference is running timer:apply_interval from the cli vs from
> inside a module, it looks like.
>
> thx,
>
> -wes
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>    
If getc is exported it is being called every three seconds with your code.
It just does not produce any visible output (returns a string, but how 
would you see that?). Change your code to getc() -> io:format("yep~n"). 
to see stuff happen.

Regards,
Zoltan.





More information about the erlang-questions mailing list