RSS Amplifier

Overcoming Software · Nov 17, 2022

reserving the name

0
Sign in to vote or save

Matt Parsons · Overcoming Software

wow i would actually really like to switch from GitHub Pages for my programming stuff, but Substack doesn’t let you use markdown? absolutely not

what about embedding a gist:

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

{-# language OverloadedStrings, NumericUnderscores, ImportQualifiedPost #-}
module Lib where
import Data.Typeable
import Control.Monad
import Prelude hiding (log)
import Data.Text (Text)
import Data.Text qualified as Text
import Say
import UnliftIO.Concurrent
import UnliftIO.Exception
import System.Posix.Process
import System.Posix.Signals qualified as Posix (Handler (Catch), installHandler, sigTERM)
import System.Exit (ExitCode(..))
log :: Text -> IO ()
log msg = do
tid <- myThreadId
say $ mconcat
[ "[", Text.pack $ show tid, "]\t\t"
, msg
]
tshow :: Show a => a -> Text
tshow = Text.pack . show
someFunc :: IO ()
someFunc = do
log "Starting App"
mainThread <- myThreadId
void (Posix.installHandler Posix.sigTERM (Posix.Catch (shutdown mainThread)) Nothing)
procId <- getProcessID
log $ mconcat ["ProcessID: ", tshow procId]
forkFinally (do
tid <- myThreadId
void (Posix.installHandler Posix.sigTERM (Posix.Catch (shutdown tid)) Nothing)
forever loop
) $ \eerr ->
case eerr of
Left (SomeException err) -> do
log $ mconcat ["Received exception: ", tshow err]
log $ mconcat ["Exception type: ", tshow (typeOf err)]
Right () ->
log "Exited successfully"
forever loop `finally` log "Exiting with Finally"
where
loop = do
threadDelay 1_000_000
log "Waiting . . ."
shutdown tid = do
log "Shutting down gracefully"
throwTo tid ExitSuccess

ah well the unicode character thing is really unfortunate

main :: IO ()
main = do
    putStrLn "really, no syntax highlighting?? really???"

No posts

Read the original on overcomingsoftware.substack.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.