scrive / pool

A high-performance striped resource pooling implementation for Haskell
Other
18 stars 11 forks source link

A more general monad for `withResource`? #30

Open thomasjm opened 1 year ago

thomasjm commented 1 year ago

Version 0.3.0.0 changed the type of withResource from

MonadBaseControl IO m => Pool a -> (a -> m b) -> m b

to

Pool a -> (a -> IO r) -> IO r

I'm not the biggest fan of MonadBaseControl, but it was nice to be able to do withResource in more general monad stacks. Would it be possible to bring something like that back? I think MonadUnliftIO is a nice candidate.

P.S. Thanks for maintaining this library!

debug-ito commented 1 year ago

I'd like some generalized versions, too. MonadMask can be another candidate.

arybczak commented 1 year ago

There exists https://hackage.haskell.org/package/unliftio-pool :slightly_smiling_face:

debug-ito commented 1 year ago

Nice! Thanks!

clintonmead commented 2 months ago

This should do the job:

withResourceM :: MonadBaseControl IO m => Pool a -> (a -> m b) -> m b
withResourceM pool func = control $ \run -> Pool.withResource pool (run . func)

Feel free to add it to the library (or steal it for another library).

madf commented 1 week ago

This should do the job:

withResourceM :: MonadBaseControl IO m => Pool a -> (a -> m b) -> m b
withResourceM pool func = control $ \run -> Pool.withResource pool (run . func)

Feel free to add it to the library (or steal it for another library).

Thanks! It saved my day!