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 low level createConnection/disposeConnection as an alternative to withConnection #527

Closed

Conversation

thomasjm
Copy link
Contributor

@thomasjm thomasjm commented Feb 7, 2024

I basically needed these functions for UnliftIO reasons. I wanted to use http-client to access a WebSocket endpoint, where I need to read and write interactively, as you would with withConnection.

However, withConnection wasn't cutting it, because it runs in the IO monad, while I want to use a more general monad. IIRC I wasn't able to use MonadUnliftIO to get around it. So I think it would be nice to expose these functions, so users can do general bracket-style stuff with them.

@snoyberg
Copy link
Owner

snoyberg commented Feb 8, 2024

Does this do what you're looking for?

liftedWithConnection :: MonadUnliftIO m => Request -> Manager -> (Connection -> m a) -> m a
liftedWithConnection req manager inner =
    withRunInIO $ \run -> withConnection req manager (run . inner)

@thomasjm
Copy link
Contributor Author

Actually yes, I was able to make my monad be MonadUnliftIO and this works. Thanks!

IIRC an earlier version of my code used a monad that was incompatible with MonadUnliftIO, so maybe there's still a use-case for separate functions. But I'm happy now--sorry for the noise.

@thomasjm thomasjm closed this Feb 29, 2024
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

Successfully merging this pull request may close these issues.

2 participants