git.iko.soy/typeable/katip-rollbar
on master help sign in
Extract function
commit564452e545e11b09a3926006bb100d290dc7193f authorjoneshf <jones3.hardy@gmail.com> dateMon 19 Feb 2018, 00:52 (9 years ago) parentf1efcf5
1 file changed+19−10
src/Katip/Scribes/Rollbar.hs+19−10
src/Katip/Scribes/Rollbar.hs+19−10
@@ -9,7 +9,7 @@ module Katip.Scribes.Rollbar where
99
1010import Prelude hiding (error)
1111
12−import "base" Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
12+import "base" Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar, takeMVar)
1313import "base" Control.Monad (replicateM, when)
1414import "base" Data.Foldable (for_)
1515import "base" Data.Functor (void)
@@ -74,15 +74,7 @@ mkRollbarScribe ::
7474mkRollbarScribe proxy accessToken manager severity verbosity = do
7575 queue <- newTBMQueueIO queueSize
7676 finalize <- newEmptyMVar
77− void $ async $ do
78− -- Setup the workers and wait until the finalizer is evaluated.
79− -- Then, close the queueu, wait for the workers and continue finalization.
80− workers <- replicateM workerSize (async $ mkWorker proxy manager queue)
81− takeMVar finalize
82− atomically $ do
83− closeTBMQueue queue
84− for_ workers waitCatchSTM
85− putMVar finalize ()
77+ setupWorkers proxy queue finalize manager
8678 let liPush item = when (permitItem severity item) $
8779 atomically (writeTBMQueue queue $ rollbarItem' item)
8880 rollbarItem' item = rollbarItem proxy accessToken item verbosity
@@ -118,6 +110,23 @@ rollbarItem _ accessToken item verbosity = Item { accessToken, itemData }
118110 value :: Value
119111 value = itemJson verbosity item
120112
113+-- | Setup the workers and wait until the finalizer is evaluated.
114+-- Then, close the queueu, wait for the workers and continue finalization.
115+setupWorkers ::
116+ RemoveHeaders headers =>
117+ proxy headers ->
118+ TBMQueue (Item Value ("Authorization" ': headers)) ->
119+ MVar () ->
120+ Manager ->
121+ IO ()
122+setupWorkers proxy queue finalize manager = void $ async $ do
123+ workers <- replicateM workerSize (async $ mkWorker proxy manager queue)
124+ takeMVar finalize
125+ atomically $ do
126+ closeTBMQueue queue
127+ for_ workers waitCatchSTM
128+ putMVar finalize ()
129+
121130mkWorker ::
122131 (RemoveHeaders headers) =>
123132 proxy headers ->