File: Internal.hs

package info (click to toggle)
haskell-streaming-commons 0.2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 280 kB
  • sloc: haskell: 2,521; ansic: 297; makefile: 7
file content (37 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Data.Streaming.Process.Internal
    ( StreamingProcessHandle (..)
    , InputSource (..)
    , OutputSink (..)
    ) where

import           Control.Concurrent.STM (TMVar)
import           System.Exit            (ExitCode)
import           System.IO              (Handle)
import           System.Process         (ProcessHandle, StdStream (CreatePipe))

-- | Class for all things which can be used to provide standard input.
--
-- Since 0.1.4
class InputSource a where
    isStdStream :: (Maybe Handle -> IO a, Maybe StdStream)
instance InputSource Handle where
    isStdStream = (\(Just h) -> return h, Just CreatePipe)

-- | Class for all things which can be used to consume standard output or
-- error.
--
-- Since 0.1.4
class OutputSink a where
    osStdStream :: (Maybe Handle -> IO a, Maybe StdStream)
instance OutputSink Handle where
    osStdStream = (\(Just h) -> return h, Just CreatePipe)

-- | Wraps up the standard @ProcessHandle@ to avoid the @waitForProcess@
-- deadlock. See the linked documentation from the module header for more
-- information.
--
-- Since 0.1.4
data StreamingProcessHandle = StreamingProcessHandle
    ProcessHandle
    (TMVar ExitCode)
    (IO ()) -- cleanup resources