Skip to content

Expose open/close for connection pooling #13

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dminuoso
Copy link

This change makes the necessary changes to the library to support pooling of resources.

Using resource-pool one can now do the following:

withLdap' :: Pool LdapH
          -> (Ldap -> IO a)
          -> IO a
withLdap' pool act = do
  (ldapH, local) <- takeResource pool
  res <- runsInEither act ldapH `E.onException` destroyResource pool local ldapH
  case res of
    Right a -> putResource local ldapH *> pure a
    Left e -> destroyResource pool local ldapH *> throwIO e

Or if you want to do this with unliftio you could do:

withLdap :: MonadUnliftIO m
         => Pool LdapH
         -> (Ldap -> m a)
         -> m a
withLdap pool act = withRunInIO $ \io -> do
  (ldapH, local) <- liftIO (takeResource pool)
  res <- liftIO (runsInEither (io . act) ldapH) `onException` liftIO (destroyResource pool local ldapH)
  case res of
    Right a -> liftIO (putResource local ldapH) *> pure a
    Left e  -> liftIO (destroyResource pool local ldapH) *> throwIO e

The change is backwards compatible.

Along the changes this also now properly catches async exceptions send to one of the worker threads.

@dminuoso
Copy link
Author

This fixes #2 and #3

@dminuoso
Copy link
Author

Test suite now finishes.

I've taken the liberty to make some minor refactoring as well.

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.

1 participant