Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* React switch with newly created events.
@ 2009-12-23 12:37 Guillaume Yziquel
  2009-12-23 13:23 ` Daniel Bünzli
  0 siblings, 1 reply; 3+ messages in thread
From: Guillaume Yziquel @ 2009-12-23 12:37 UTC (permalink / raw)
  To: OCaml List, Daniel Bünzli

Hello.

I've recently been working again of React, and I have the following 
question. Current code is below.

I'm creating an event with React.E.switch, that creates a new event 
through the schedule function, and this new events replaces the old 
event. React.E.switch is used for this replacement.

React.E.switch initial_event (React.E.map begin function () -> schedule 
(rescheduler ()) end tick)

However, it may happen (and it does happen) that as soon as this new 
React.event is created, an event is fired before the React.E.switch has 
been executed to replace the old event by the new event.

This is due to Lwt concurrency.

I therefore have two potential solutions:

-1- clutter my code with mutexes to synchronise the whole stuff, with 
the disadvantage that there is not, to my knowledge, to execute a 
function just after the React.E.switch function has effectively switched 
events.

-2- look for a way in React to do it within React only. Which would mean 
to somehow implement within React a way to switch to a newly created 
event, without race conditions.

What would you do in this context?

Here's the code:

> let reschedule ?attach:(f = begin fun x -> x end) start rescheduler =
>   (* The let define tick in E.fix define is the proper way to
>      implement recursive events. define has type React.event ->
>      (React.event * React.event) and its argument is a placeholder
>      for the event at time t-dt. *)
>   let attach initial_event =
>     let define tick =
>       (* Here is something I worry about: It is possible that the event created
>          with the schedule function is fired before it is attached to the switched
>          event, hence losing an event, and stalling the whole regular event. *)
>       let tick' = React.E.switch initial_event (React.E.map
>         begin function () -> schedule (rescheduler ()) end tick) in
>       tick', tick'
>     in f (React.E.fix define) in
>   schedule ~attach:attach start
> 
> let regular_schedule ?attach:(f = begin fun x -> x end) start period =
>   reschedule ~attach:f start (fun () -> Calendar.add (Calendar.now ()) period)

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-23 13:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-23 12:37 React switch with newly created events Guillaume Yziquel
2009-12-23 13:23 ` Daniel Bünzli
2009-12-23 13:54   ` Guillaume Yziquel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox