[newbie] Erlangish way of Iterator pattern

Bengt Kleberg bengt.kleberg@REDACTED
Tue Jan 25 16:34:47 CET 2005

Gaspar Chilingarov wrote:
> what i have in erlang -- i have erlang process, which can accept data
> messages and eof messages and do processing. another process hangs
> around, waiting for TCP connection and feeding first process with data
> read from TCP. in the same time i have shell script which runs once a
> minute and feeds data from some file(or piped command line) to TCP port.

please note that it is possible to use active mode (see 
http://www.corelatus.com/~matthias/modules.html the gen_tcp module).
unless you want a permanent process for processing, you could let the 
process that waits for a tcp connection start a new process and redirect 
(gen_tcp:controlling_process/2) the incoming messages to the new process.

> now i want to get rid of shell script, but i wish to have separate
> module which will do this -- i.e. 1. running periodically external
> command, 2. feeding to another process.
> are there any idioms in Erlang for this or it should be implemented in
> straight way -- i.e. just another process sitting there and doing it's
> job -- file reading/parsing/feeding to another process ?

i would recommend just another process. look at timer:apply_interval/4 
if you want to run something periodically.


More information about the erlang-questions mailing list