@@ -43,6 +43,7 @@ import Text.Printf ( printf )
43
43
44
44
import Paths_acid_state ( version )
45
45
import Data.Version ( showVersion )
46
+ import Control.Exception ( handle , IOException )
46
47
47
48
type EntryId = Int
48
49
@@ -87,7 +88,8 @@ openFileLog identifier = do
87
88
currentState <- newEmptyMVar
88
89
queue <- newTVarIO ([] , [] )
89
90
nextEntryRef <- newTVarIO 0
90
- tid2 <- forkIO $ fileWriter currentState queue
91
+ tid1 <- myThreadId
92
+ tid2 <- forkIO $ fileWriter currentState queue tid1
91
93
let fLog = FileLog { logIdentifier = identifier
92
94
, logCurrent = currentState
93
95
, logNextEntryId = nextEntryRef
@@ -105,16 +107,17 @@ openFileLog identifier = do
105
107
putMVar currentState handle
106
108
return fLog
107
109
108
- fileWriter :: MVar FHandle -> TVar ([Lazy. ByteString ], [IO () ]) -> IO ()
109
- fileWriter currentState queue = forever $ do
110
+ fileWriter :: MVar FHandle -> TVar ([Lazy. ByteString ], [IO () ]) -> ThreadId -> IO ()
111
+ fileWriter currentState queue parentTid = forever $ do
110
112
(entries, actions) <- atomically $ do
111
113
(entries, actions) <- readTVar queue
112
114
when (null entries && null actions) retry
113
115
writeTVar queue ([] , [] )
114
116
return (reverse entries, reverse actions)
115
- withMVar currentState $ \ fd -> do
116
- let arch = Archive. packEntries entries
117
- writeToDisk fd (repack arch)
117
+ handle (\ e -> throwTo parentTid (e :: IOException )) $
118
+ withMVar currentState $ \ fd -> do
119
+ let arch = Archive. packEntries entries
120
+ writeToDisk fd (repack arch)
118
121
sequence_ actions
119
122
yield
120
123
0 commit comments