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

A more general monad for withResource? #30

Open
thomasjm opened this issue Mar 16, 2023 · 4 comments
Open

A more general monad for withResource? #30

thomasjm opened this issue Mar 16, 2023 · 4 comments

Comments

@thomasjm
Copy link

thomasjm commented Mar 16, 2023

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
Copy link

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

@arybczak
Copy link
Contributor

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

@debug-ito
Copy link

Nice! Thanks!

@clintonmead
Copy link

clintonmead commented Apr 24, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants