[server] Adjust TreeModule structure

This commit prepares a slighly more powerful TreeModule structure: Now,
TreeModules can finish their execution, which should make some kinds of menus
and transitions possible.
This commit is contained in:
Joscha 2020-02-13 23:12:28 +00:00
parent d08f858692
commit 220b5a3234
4 changed files with 26 additions and 18 deletions

View file

@ -3,6 +3,7 @@
module Forest.Util
( findPrev
, findNext
, whileM
, withThread
, sendPacket
, closeWithErrorMessage
@ -25,6 +26,14 @@ findNext f as = snd <$> find (f . fst) (zip as $ tail as)
withThread :: IO () -> IO () -> IO ()
withThread thread main = withAsync thread $ const main
-- | Run a monadic action until it returns @False@ for the first time.
whileM :: Monad m => m Bool -> m ()
whileM f = do
continue <- f
if continue
then whileM f
else pure ()
sendPacket :: ToJSON a => WS.Connection -> a -> IO ()
sendPacket conn packet = WS.sendTextData conn $ encode packet