mirror of
https://github.com/quantum9Innovation/suntheme.git
synced 2024-11-25 01:43:50 -08:00
f22d715b8e
introduce Workers, Cache modules and shuffle around some existing functions
31 lines
861 B
Haskell
31 lines
861 B
Haskell
module Sugar where
|
|
|
|
import Pure (kill)
|
|
import Types (Status(..))
|
|
|
|
import System.Exit (ExitCode(ExitFailure), exitWith)
|
|
import System.Process (readProcess)
|
|
import Control.Exception (SomeException, catch)
|
|
|
|
throw :: (Monoid m) => SomeException -> IO m
|
|
throw e = print e >> return mempty
|
|
|
|
continue :: (Status s) => s -> IO () -> IO ()
|
|
continue e err = (putStrLn . disp) e >> err
|
|
|
|
failure :: SomeException -> IO ()
|
|
failure = print
|
|
|
|
destruct :: (Status s) => s -> IO () -> IO () -> IO ()
|
|
destruct status success unsuccessful
|
|
| ok status = success
|
|
| otherwise = continue status unsuccessful
|
|
|
|
crash :: IO ()
|
|
crash = (exitWith . ExitFailure) 1
|
|
|
|
exec :: String -> (SomeException -> IO String) -> IO String
|
|
exec cmd = catch (readProcess "bash" ["-c", cmd] "")
|
|
|
|
killall :: [String] -> [IO String]
|
|
killall = map (dispatch . kill) where dispatch cmd = exec cmd throw
|