caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: caml-list@inria.fr
Subject: React.E.switch issue.
Date: Thu, 24 Sep 2009 09:40:20 +0200	[thread overview]
Message-ID: <4ABB2264.1090409@citycable.ch> (raw)

Hello.

Here is a piece of code that I am having issue. I'm trying to use React 
to parse reactively a server output. I have the following event definition:

>   let event_starting_at str = React.E.fold begin fun accu chunk -> accu^chunk end str received_event in 
>   let to_be_parsed_event_of_event, set_to_be_parsed_event_of_event = React.E.create () in
>   let to_be_parsed_event = React.E.switch (event_starting_at "") to_be_parsed_event_of_event in
>   let reinitialise_with unparsed_text = set_to_be_parsed_event_of_event (event_starting_at unparsed_text) in

String chunks from the server are received by the 'received_event' 
event, on the first line.

My issue is that the 'reinitialise_with' function is called in a 
function 'phi' which is used in the following way:

let message_event = React.E.map phi to_be_parsed_event.

phi is the parsing function, so I'm not reproducing it directly here. 
However, you would have the behaviour described further below with the 
following code:

let phi string_chunk =
   let new_string_chunk = String.copy string_chunk in
   reinitialise_with new_string_chunk;
   new_string_chunk

This creates hiccups in the events.

For example, at different time intervals, with to_be_parsed_event, I get:

	q
	qqw
	qqwwe
	qqwweer
	qqwweerrt

etc... where I'd like in fact to have

	q
	qw
	qwe
	qwer
	qwert

Advice would be appreciated on how to correct this.

All the best,

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/


             reply	other threads:[~2009-09-24  7:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-24  7:40 Guillaume Yziquel [this message]
2009-09-24  8:01 ` Guillaume Yziquel
2009-09-24 13:42 ` Daniel Bünzli
2009-09-24 14:14   ` Guillaume Yziquel
2009-09-28 11:57     ` Daniel Bünzli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ABB2264.1090409@citycable.ch \
    --to=guillaume.yziquel@citycable.ch \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@erratique.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).