Skip to content

Commit

Permalink
Merge pull request #24 from well-typed/jdral/issue-19
Browse files Browse the repository at this point in the history
Add `withIOCtx`
  • Loading branch information
dcoutts authored Dec 11, 2024
2 parents ab50126 + 553fbef commit 5400fe5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
index-state:
-- Bump this if you need newer packages from Hackage
-- current date: quickcheck-lockstep-0.6.0
, hackage.haskell.org 2024-12-10T00:00:00Z

packages: .
8 changes: 6 additions & 2 deletions src/System/IO/BlockIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ module System.IO.BlockIO (

-- * I\/O context and initialisation
IOCtx,
initIOCtx,
IOCtxParams(..),
defaultIOCtxParams,
withIOCtx,
initIOCtx,
closeIOCtx,

-- * Performing I\/O
Expand All @@ -34,7 +35,7 @@ import Control.Concurrent.MVar
import Control.Concurrent.QSemN
import Control.Concurrent.Chan
import Control.Exception (mask_, throw, ArrayException(UndefinedElement),
finally, assert, throwIO)
finally, assert, throwIO, bracket)
import System.IO.Error
import GHC.IO.Exception (IOErrorType(ResourceVanished, InvalidArgument))

Expand Down Expand Up @@ -90,6 +91,9 @@ defaultIOCtxParams =
ioctxConcurrencyLimit = 64 * 3
}

withIOCtx :: IOCtxParams -> (IOCtx -> IO a) -> IO a
withIOCtx params = bracket (initIOCtx params) closeIOCtx

initIOCtx :: IOCtxParams -> IO IOCtx
initIOCtx IOCtxParams {ioctxBatchSizeLimit, ioctxConcurrencyLimit} = do
#if MIN_VERSION_base(4,16,0)
Expand Down

0 comments on commit 5400fe5

Please sign in to comment.