Skip to content

Commit

Permalink
Add withIOCtx
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisdral committed Dec 10, 2024
1 parent ab50126 commit 11f3cf8
Showing 1 changed file with 6 additions and 2 deletions.
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 11f3cf8

Please sign in to comment.