[erlang-questions] how to use timer:apply_interval/4

Paul Mineiro <>
Mon Jul 20 20:02:59 CEST 2009


You can cheese it by bouncing your apply off erlang:apply/2 which is
exported etc. but which can take a fun reference.

------
#! /usr/bin/env escript

-mode (compile).

do_task (A) ->
  io:format ("~w: now=~w~n", [ A, now () ]).

main (_) ->
  io:format ("starting \n"),
  { ok, _ } =
    timer:apply_interval (80, erlang, apply, [ fun do_task/1, [ "info" ]
]),
  timer:sleep (100),
  io:format ("ending \n").
------

-- p

On Sun, 19 Jul 2009, Richard Andrews wrote:

> An escript has no module.
>
> do_task would need to be exported and it would need to be exported
> from a module. As a result there is no way to call it.
> Similarly the error comes from the fact that there is no module and as
> a result ?MODULE expands to (presumably) some internal implementation
> value inserted by escript.
>
> HTH
> --
>   Rich
>
>
> On Sun, Jul 19, 2009 at 2:01 PM, Oscar<> wrote:
> >  1 #!/usr/bin/env escript
> >  2
> >  3 do_task(A) ->
> >  4     io:format("~w: now=~w~n", [A, now()]).
> >  5
> >  6 main(_) ->
> >  7     io:format("starting \n"),
> >  8     {ok, _} = timer:apply_interval(80, ?MODULE, do_task,["info"]),
> >  9     timer:sleep(100),
> >  10     io:format("ending \n").
> >
> >
> >
> > :~/work/erlang/flower$ ./timer_main.erl
> > ./timer_main.erl:3: Warning: function do_task/1 is unused
> > starting
> >
> > =ERROR REPORT==== 19-Jul-2009::11:57:29 ===
> > Error in process <0.33.0> with exit value:
> > {undef,[{'escript__timer_main.erl__1247__975849__641609',do_task,["info"]}]}
> >
> > ending
> >
> >
> >
> >
> > I have two questions:
> > 1. how to explain the error log?
> > 2. how to get rid of the warning ''function do_task/1 is unused'?
> >
> > ________________________________________________________________
> > erlang-questions mailing list. See http://www.erlang.org/faq.html
> > erlang-questions (at) erlang.org
> >
> >
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>



More information about the erlang-questions mailing list