Skip to content

Commit

Permalink
Use deepseq
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jun 23, 2012
1 parent 0f9d857 commit 29568df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 5 additions & 1 deletion silently.cabal
Expand Up @@ -25,7 +25,10 @@ source-repository head
location: https://github.com/trystan/silently

Library
build-depends: base >=4 && <=5, directory -any
build-depends:
base >=4 && <=5
, directory
, deepseq
exposed-modules: System.IO.Silently
exposed: True
buildable: True
Expand Down Expand Up @@ -66,3 +69,4 @@ test-suite spec
base
, hspec-shouldbe
, directory
, deepseq
7 changes: 2 additions & 5 deletions src/System/IO/Silently.hs
Expand Up @@ -10,6 +10,7 @@ module System.IO.Silently (
import GHC.IO.Handle (hDuplicate, hDuplicateTo)
import System.IO
import Control.Exception (bracket)
import Control.DeepSeq
import System.Directory (removeFile,getTemporaryDirectory)

nullDevice :: FilePath
Expand Down Expand Up @@ -66,13 +67,9 @@ hCapture handles action = do
mapM_ hFlush handles
hClose tmpHandle
str <- readFile tmpFile
forceList str
return (str,a)
str `deepseq` return (str,a)
go hs = goBracket go tmpHandle hs

forceList [] = return ()
forceList (x:xs) = forceList xs

goBracket :: ([Handle] -> IO a) -> Handle -> [Handle] -> IO a
goBracket go tmpHandle (h:hs) = bracket (do old <- hDuplicate h
hDuplicateTo tmpHandle h
Expand Down

0 comments on commit 29568df

Please sign in to comment.