eventstore-0.1.0.1: Database/EventStore/Internal/Writer.hs
--------------------------------------------------------------------------------
-- |
-- Module : Database.EventStore.Internal.Writer
-- Copyright : (C) 2014 Yorick Laupa
-- License : (see the file LICENSE)
--
-- Maintainer : Yorick Laupa <yo.eight@gmail.com>
-- Stability : provisional
-- Portability : non-portable
--
--------------------------------------------------------------------------------
module Database.EventStore.Internal.Writer (writerThread) where
--------------------------------------------------------------------------------
import Control.Monad
import Control.Concurrent.STM
import qualified Data.ByteString as B
import System.IO
--------------------------------------------------------------------------------
import Data.Serialize.Put
--------------------------------------------------------------------------------
import Database.EventStore.Internal.Packages
import Database.EventStore.Internal.Types
--------------------------------------------------------------------------------
writerThread :: TChan Package -> Handle -> IO ()
writerThread chan hdl = forever $ do
pkg <- atomically $ readTChan chan
B.hPut hdl (runPut $ putPackage pkg)
hFlush hdl