I have the following line of code that uses aeson
to serialize an IntMap
and save the JSON to disk, all on a child thread:
import Data.Aeson (encode, toJSON)
import Data.Conduit (($$), (=$), yield)
import qualified Data.ByteString.Lazy as BL (toStrict)
import qualified Data.Conduit.Binary as CB (sinkFile)
import qualified Data.Conduit.List as CL (map)
-- ...
forkIO . runResourceT $ yield (toJSON intMap) $$ CL.map (BL.toStrict . encode) =$ CB.sinkFile file
I would like to ensure that this code cannot be interrupted by any asynchronous exceptions. My fear is that an interruption could result in incomplete/corrupt data on disk.
What can I do in this case to ensure immunity from async exceptions? Is it possible to ensure that the child thread will be allowed to finish even if main
wants to terminate?
Thanks!