fl00r/em-pg-sequel — pull request #4 by royaltm (2013-10-04 17:53:58+00:00)
Title: bug fixes + play nice with transactions and disconnects

Hi @fl00r,

I've finally had an opportunity to use this gem myself. I really like your idea of patching seuqel connection pool instead of adapter - the connection pool is the place where Client to Fiber assignment takes place.

Everything was good until I've noticed that after disconnecting from postgress server the pool became broken. Fortunately it was easy to fix - [64daa3d](https://github.com/royaltm/em-pg-sequel/commit/64daa3d33f6dc43342b5a6dcaab196e033ba623b)

I thought it would be nice to pass symbol instead of Class to :pool_class option so I did [f9024ce](https://github.com/royaltm/em-pg-sequel/commit/f9024ceb1420cbb615aa40e43b9a58f5c416ab45).

Then I needed transactions. This wasn't so simple at first because connection pool didn't yield the same connection to the same fiber, as it was supposed to.

So I needed to rewrite pool acquisition logic taking sequel threaded pool as an example. As a side effect the pool is now making connections dynamically when it needs to. This doesn't hurt as em-pg-client makes connections in fully async manner. I think it actually helps as it reduces unnecessary traffic at the start when you expect your pool to grow to numbers.

The last commit [d9d687e](https://github.com/royaltm/em-pg-sequel/commit/https://github.com/royaltm/em-pg-sequel/commit/d9d687e53ed1b86f3e48d78938aded3ddd63e4d5) is optional - it collapses both classes to one connection_pool class. But there might be reasons you've made connection_pool classes separated I might not be aware of.

To make use of autoreconnect feature the connection must be made like this:

```ruby

Sequel.connect(url, pool_class: :em_synchrony,
after_connect: proc {|pg| pg.async_autoreconnect = true})

```

as there is no way to pass em-pg-client custom parameters to Sequel.connect. However :connect_timeout should work.