verement / lmdb-simple

Simple Haskell API for LMDB
https://hackage.haskell.org/package/lmdb-simple
BSD 3-Clause "New" or "Revised" License
12 stars 11 forks source link

MonadUnliftIO compatibility #4

Open ramirez7 opened 5 years ago

ramirez7 commented 5 years ago

This PR helps make the Transaction type compatible with things that require MonadUnliftIO.

My motivation for this change was using Transaction together with ResourceT. runResourceT has a MonadUnliftIO constraint on it. The current lmdb-simple public API doesn't expose enough information to even write a newtype/orphan MonadUnliftIO instance for Transaction.

I implemented this in a dependency-less way: transactionWithRunInIO is the withRunInIO implementation for Transaction, and consumers of lmdb-simple can use it to write MonadUnliftIO for newtypes around Transaction.

If you don't mind taking on an unliftio-core dependency, I'd be happy to include a MonadUnliftIO instance instead. unliftio-core itself is very lightweight, only depending on base and transformers.