2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
|
|
|
Convenient Re-Exports
|
|
|
|
-}
|
|
|
|
|
2020-01-24 08:28:38 +03:00
|
|
|
module Urbit.Prelude
|
2019-07-16 03:01:45 +03:00
|
|
|
( module ClassyPrelude
|
2019-07-24 04:34:16 +03:00
|
|
|
, module Control.Arrow
|
2019-07-16 03:01:45 +03:00
|
|
|
, module Control.Lens
|
2019-07-20 06:00:23 +03:00
|
|
|
, module Data.Acquire
|
2019-08-28 14:45:49 +03:00
|
|
|
, module Data.RAcquire
|
2019-07-21 07:13:21 +03:00
|
|
|
, module Data.Void
|
2020-01-24 08:28:38 +03:00
|
|
|
, module Urbit.Noun
|
2019-07-21 07:13:21 +03:00
|
|
|
, module Text.Show.Pretty
|
|
|
|
, module Text.Printf
|
2019-08-28 14:45:49 +03:00
|
|
|
, module RIO
|
|
|
|
, io, rio
|
|
|
|
, logTrace
|
2020-10-15 03:05:56 +03:00
|
|
|
, acquireWorker, acquireWorkerBound
|
2020-12-03 22:13:59 +03:00
|
|
|
, hark
|
2019-07-16 03:01:45 +03:00
|
|
|
) where
|
|
|
|
|
|
|
|
import ClassyPrelude
|
2020-01-24 08:28:38 +03:00
|
|
|
import Urbit.Noun
|
2019-07-20 06:00:23 +03:00
|
|
|
|
2019-07-24 04:34:16 +03:00
|
|
|
import Control.Arrow ((<<<), (>>>))
|
2020-10-27 15:22:33 +03:00
|
|
|
import Control.Lens hiding (Each, Index, cons, index, snoc, uncons, unsnoc,
|
|
|
|
(<.>), (<|))
|
2019-07-21 07:13:21 +03:00
|
|
|
import Data.Acquire (Acquire, mkAcquire, with)
|
2019-10-22 21:25:04 +03:00
|
|
|
import Data.RAcquire (RAcquire, mkRAcquire, rwith)
|
|
|
|
import Data.RAcquire (MonadAcquire(..), MonadRIO(..))
|
2019-07-21 07:13:21 +03:00
|
|
|
import Data.Void (Void, absurd)
|
|
|
|
import Text.Printf (printf)
|
2019-07-24 04:34:16 +03:00
|
|
|
import Text.Show.Pretty (pPrint, ppShow)
|
2019-08-28 14:45:49 +03:00
|
|
|
|
|
|
|
import RIO (RIO, runRIO)
|
|
|
|
import RIO (Utf8Builder, display, displayShow)
|
|
|
|
import RIO (threadDelay)
|
2020-08-16 20:33:52 +03:00
|
|
|
import RIO (HasLogFunc, LogFunc, LogLevel(..), logDebug, logError, logFuncL,
|
|
|
|
logInfo, logOptionsHandle, logOther, logWarn, mkLogFunc,
|
|
|
|
setLogMinLevel, setLogUseLoc, setLogUseTime, withLogFunc)
|
2019-08-28 14:45:49 +03:00
|
|
|
|
2020-12-03 22:13:59 +03:00
|
|
|
import qualified RIO
|
|
|
|
|
2019-08-28 14:45:49 +03:00
|
|
|
io :: MonadIO m => IO a -> m a
|
|
|
|
io = liftIO
|
|
|
|
|
|
|
|
rio :: MonadRIO m => RIO e a -> m e a
|
|
|
|
rio = liftRIO
|
|
|
|
|
|
|
|
logTrace :: HasLogFunc e => Utf8Builder -> RIO e ()
|
|
|
|
logTrace = logOther "trace"
|
2020-10-15 03:05:56 +03:00
|
|
|
|
2020-12-03 22:13:59 +03:00
|
|
|
-- | Composes a log message out of textual components.
|
|
|
|
hark :: [Text] -> Utf8Builder
|
|
|
|
hark = RIO.displayBytesUtf8 . foldMap encodeUtf8
|
2020-10-15 03:05:56 +03:00
|
|
|
|
|
|
|
-- Utils for Spawning Worker Threads -------------------------------------------
|
|
|
|
|
|
|
|
acquireWorker :: HasLogFunc e => Text -> RIO e () -> RAcquire e (Async ())
|
|
|
|
acquireWorker nam act = mkRAcquire (async act) kill
|
|
|
|
where
|
|
|
|
kill tid = do
|
|
|
|
logInfo ("Killing worker thread: " <> display nam)
|
|
|
|
cancel tid
|
|
|
|
|
|
|
|
acquireWorkerBound :: HasLogFunc e => Text -> RIO e () -> RAcquire e (Async ())
|
|
|
|
acquireWorkerBound nam act = mkRAcquire (asyncBound act) kill
|
|
|
|
where
|
|
|
|
kill tid = do
|
|
|
|
logInfo ("Killing worker thread: " <> display nam)
|
|
|
|
cancel tid
|
|
|
|
|