Hi Erik, there seem to be several options. Tie simplest one is that you'll call getEvent with some reasonable timeout in a loop and check some communication channel an update from the calculation thread.
Probably the correct way how to handle it involves three threads: (1) The computation thread writes its updates to a channel of type Either Event ComputationUpdate using Right. (2) Another thread calls getEvent repeatedly and writes received events to the channel using Left. (3) A consuming thread (the one for Ncurses UI) consumes the channel and reacts both to computation updates and Ncurses events. However, I'm not sure if Ncurses doesn't mind calling getEvent from a different thread than the one that updates UI. For the communication channel, I'd probably use TQueue (or TBQueue, if there is a risk of writing values too fast). Best regards, Petr Pudlak 2013/1/26 Erik de Castro Lopo <[email protected]> > Hi all, > > I am in the process of writing a Haskell program consisting of two > threads, one for performing a calculation and one for an Ncurses UI > (haskell-ncurses). > > The calculation thread needs to feed a stream of numbers back to the > UI thread (about 1 value per second) and the UI needs to take input > from the user and will pass parameter changes to the calculation > thread using an IORef and atomicModifyIORef. > > However, I'm not sure how to hande the UI thread. The UI thread would > normally wait for Ncurses input using getEvent, but I need advice on > how to the the data from the calculation thread. > > Any advice or things to try? > > Cheers, > Erik > -- > ---------------------------------------------------------------------- > Erik de Castro Lopo > http://www.mega-nerd.com/ > > _______________________________________________ > Haskell-Cafe mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe >
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
