haskell - Pipes.Concurrent: Sent signal is delivered one click later than expected -


i'm using pipes.concurrent write short gui program gtk. it's minesweeper-esque game, i'm constructing grid of buttons.

i construct , connect buttons with:

b <- buttonnewwithlabel (show $ adjacencies board ! i) on b buttonactivated       $ void . atomically $ send output (clicksignal (mines board ! i)) return b 

and connect pipe with:

(output, input)  <- spawn (latest (clicksignal 0 false))  let run =         sig <- await         case sig of             clicksignal ismine ->                 if ismine                                     lift $ labelsettext info (show ++ " -- lose!")                 else                      lift $ labelsettext info (show ++ " -- ok")                     run             empty ->                 lift $ labelsettext info "empty case"                 run  void . forkio $      runeffect $ frominput input >-> run     performgc 

it runs almost expected. if click on button 1, nothing happens. if press button 23, update info label "1..". if click on button, update "23..", , forth.

i suspect either i'm failing understand how concurrent pipes meant work on level or lazy io doing weird.

using latest buffering strategy means there's value available read in buffer, await return immediately; , send likewise succeed, long gets chance run. test program wrote worked okay in ghci, when compiled never let thread run trying read console , send; got endless stream of 0 until terminated program.

your consumer run doesn't have in cause pause, may starving thread trying send output. if case, small threaddelay 100 or before each call run might help.

another possibility, , more efficient one, use buffer blocks consumer until there's message act on. avoid blocking event callback, use newest 1 buffer strategy, succeed send , overwrite current value if there 1 there.

if neither of help, suspect there's else going on way gui framework you're using plumbed, not familiar gtk bindings in haskell can't of that.


Comments

Popular posts from this blog

stringtemplate - StringTemplate4 if conditional with length -

shader - OpenGL Shadow Map -