-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Launcher where | ||
|
||
import Control.Concurrent.Async | ||
import Prelude | ||
import System.Process | ||
|
||
-- What is @bracket@? | ||
-- | ||
-- When you want to acquire a resource, do some work with it, and then release | ||
-- the resource, it is a good idea to use bracket, because bracket will install | ||
-- the necessary exception handler to release the resource in the event that an | ||
-- exception is raised during the computation. If an exception is raised, then | ||
-- bracket will re-raise the exception (after performing the release). | ||
-- | ||
-- http://hackage.haskell.org/package/base-4.12.0.0/docs/Control-Exception-Base.html#v:bracket | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
-- | Run an external process alongside a haskell IO action | ||
-- | ||
-- Both are expected to run forever. | ||
-- | ||
-- Sadly you cannot quit this in ghci | ||
bracketProcess :: CreateProcess -> IO () -> IO () | ||
bracketProcess process action = do | ||
_ <- withCreateProcess | ||
process {delegate_ctlc = True, std_out = CreatePipe } | ||
$ \_stdin _stdout _stderr ph -> do | ||
-- if this IO action throws, @withCreateProcess@ will kill the node and | ||
-- rethrow. | ||
concurrently action (node ph) | ||
return () | ||
where | ||
node ph = do | ||
_ <- waitForProcess ph | ||
fail "why is the node gone?" | ||
|
||
|
||
|
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
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