-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weird behavior when chaining tasks #257
Comments
I think the problem with |
Hi @Tylerwbrown! What @Deltaspace0 explains sounds reasonable. I think the I'm not sure in which package Thanks! |
@fjvallarino hey, thanks for taking a look, the packag I'm using is this one https://hackage.haskell.org/package/sleep-0.1.0.1/docs/System-Sleep.html |
@Tylerwbrown it seems I will need to revamp how the Currently, when a Funny enough, if instead of a {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
import Monomer
import Data.Functor (($>))
import System.Sleep (sleep)
data Ev = Inc | Dec | Exec deriving Eq
build _ count = vstack [ hstack [ labelS count, spacer, button "Increment" Inc ] ]
handle _ _ !count = \case
Inc -> [Model $ count + 1, Producer $ \sendMsg -> do
sleep 1
sendMsg Exec]
Exec -> [Producer $ \sendMsg -> do
sleep 1
sendMsg Dec]
Dec -> [Model $ count - 1]
main = startApp (0 :: Int) handle build [ appTheme darkTheme, appFontDef "Regular" "./Roboto-Regular.ttf" ] |
I have a more complex app, but I tried to write the simplest app to reproduce the issue:
this is on monomer 1.5.0.0 and GHC 9.2.5.
If you spam the increment button, the GUI will get choppy after the sleeps finish up, and
count
will eventually be negative, going further down depending on how much you spammed it, when really it should never go below 0.Some workarounds:
Control.Concurrent (threadDelay)
instead ofSystem.Sleep (sleep)
(this sleep seems to block threads which is probably why the choppiness occurs, as that doesn't occur with threadDelay).Exec
, just sleep for 2 seconds and immediately callDec
in the first task instead ofExec
.I'd be totally happy just using
threadDelay
, I'm just worried if I'm doing some other IO operation that blocks in a similar way toSystem.Sleep (sleep)
that this issue will arise again.The text was updated successfully, but these errors were encountered: