Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withIOCtx #24

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading