Skip to content
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

Assert in 'run' that the program is using the threaded RTS #43

Merged
merged 1 commit into from
Feb 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions gi-gtk-declarative-app-simple/src/GI/Gtk/Declarative/App/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import GI.Gtk.Declarative.EventSource
import GI.Gtk.Declarative.State
import Pipes
import Pipes.Concurrent
import System.Exit
import System.IO

-- | Describes an state reducer application.
data App window state event =
Expand Down Expand Up @@ -72,6 +74,7 @@ run
=> App window state event -- ^ Application to run
-> IO state
run app = do
assertRuntimeSupportsBoundThreads
void $ Gtk.init Nothing
Async.withAsync (runLoop app <* Gtk.mainQuit) $ \lastState -> do
Gtk.main
Expand Down Expand Up @@ -139,6 +142,17 @@ runLoop App {..} = do
loop newState newMarkup events sub newModel
Exit -> return oldModel

-- | Assert that the program was linked using the @-threaded@ flag, to
-- enable the threaded runtime required by this module.
assertRuntimeSupportsBoundThreads :: IO ()
assertRuntimeSupportsBoundThreads =
unless rtsSupportsBoundThreads $ do
hPutStrLn stderr "GI.Gtk.Declarative.App.Simple requires the program to \
\be linked using the threaded runtime of GHC (-threaded \
\flag)."
exitFailure


publishEvent :: Chan event -> event -> IO ()
publishEvent mvar = void . writeChan mvar

Expand Down