Skip to content

Commit

Permalink
add simple client pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Lupino committed Mar 12, 2018
1 parent 442b084 commit ee8649e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions periodic-client/periodic-client.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Periodic.Client
, Periodic.ClientPool
, Periodic.Job
, Periodic.Worker

Expand All @@ -29,6 +30,8 @@ library
, transformers
, lifted-base
, lifted-async

, resource-pool
default-language: Haskell2010

executable periodic
Expand Down
2 changes: 1 addition & 1 deletion periodic-client/src/Periodic/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import Periodic.Utils (getEpochTime)
import Periodic.Monad
import System.Timeout.Lifted (timeout)

type ClientT m = PeriodicT m ()
type ClientT m = PeriodicT m ()

data ClientEnv m = ClientEnv
{ periodicEnv :: Env m ()
Expand Down
23 changes: 23 additions & 0 deletions periodic-client/src/Periodic/ClientPool.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Periodic.ClientPool
(
module Periodic.Client
, ClientEnv
, runClientT
, open
) where

import Data.Pool (Pool, createPool, withResource)
import Periodic.Client hiding (ClientEnv, close, open, runClientT)
import qualified Periodic.Client as Client (ClientEnv, close, open,
runClientT)
import Periodic.Transport (Transport)

type ClientEnv = Pool (Client.ClientEnv IO)

runClientT :: ClientEnv -> ClientT IO a -> IO a
runClientT pool m = withResource pool $ flip Client.runClientT m

open
:: (Transport -> IO Transport) -> String -> Int -> IO ClientEnv
open f h =
createPool (Client.open f h) (`Client.runClientT` Client.close) 1 5000

0 comments on commit ee8649e

Please sign in to comment.