Runs a
YiM action in a separate thread.
Notes:
- It seems to work but I don't know why
- Maybe deadlocks?
- If you're outputting into the Yi window, you should really limit
the rate at which you do so: for example, the Pango front-end will
quite happily segfault/double-free if you output too fast.
I am exporting this for those adventurous to play with but I have only
discovered how to do this a night before the release so it's rather
experimental. A simple function that prints a message once a second, 5
times, could be written like this:
printer :: YiM ThreadId
printer = do
mv <- io $ newMVar (0 :: Int)
forkAction (suicide mv) MustRefresh $ do
c <- io $ do
modifyMVar_ mv (return . succ)
tryReadMVar mv
case c of
Nothing -> printMsg "messaging unknown time"
Just x -> printMsg $ "message #" <> showT x
where
suicide mv = tryReadMVar mv >>= case
Just i | i >= 5 -> return True
_ -> threadDelay 1000000 >> return False