diff --git a/cabal.project b/cabal.project index e6fdbad..94e1a92 100644 --- a/cabal.project +++ b/cabal.project @@ -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: . diff --git a/src/System/IO/BlockIO.hs b/src/System/IO/BlockIO.hs index 11c5592..419991b 100644 --- a/src/System/IO/BlockIO.hs +++ b/src/System/IO/BlockIO.hs @@ -7,9 +7,10 @@ module System.IO.BlockIO ( -- * I\/O context and initialisation IOCtx, - initIOCtx, IOCtxParams(..), defaultIOCtxParams, + withIOCtx, + initIOCtx, closeIOCtx, -- * Performing I\/O @@ -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)) @@ -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)