Parsing infinite streams style

Jay Nelson jay@REDACTED
Fri Mar 5 17:30:05 CET 2004


Joe wrote:

 > There are two ways of doing this

If the stream contains multiple interspersed data streams,
you may want to use separate processes to handle them:

<start msg 1> <start msg 2> <more msg 1> <start msg 3>
<end msg 1> ...


Inside the loop, create a new process when new msg starts.
Update State to include Pid and loop.

When more is parsed and received, send it to Pid and loop.

When end is parsed, send it with a finished tag, remove the
Pid from State and loop.

The collecting process just builds a list and then handles it when
the finished message arrives.  It runs to completion using only
the data it has been handed.

This technique can be combined with the continuation function
technique if the parsing is dependent on the previous data so
that the parsing function becomes part of the state associated
with the new Pid and encapsulates the current parse state.

jay


---------------------------------------------------
DuoMark International, Inc.
6523 Colgate Avenue, Suite 325
Los Angeles, CA  90048-4410 / USA
Voice: +1 323 381-0001
FAX: +1 323 549 0172
Email: jay@REDACTED
WWW: http://www.duomark.com/





More information about the erlang-questions mailing list