Skip to content

Expose open/close for connection pooling#13

Open
dminuoso wants to merge 4 commits intosupki:masterfrom
dminuoso:poolable
Open

Expose open/close for connection pooling#13
dminuoso wants to merge 4 commits intosupki:masterfrom
dminuoso:poolable

Conversation

@dminuoso
Copy link
Copy Markdown

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
Copy Markdown
Author

This fixes #2 and #3

@dminuoso
Copy link
Copy Markdown
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