grocer/grocer — pull request #35 by d11wtq (2013-01-30 03:57:11+00:00)
Title: Add connection pool support

As promised, here is the support for connection pooling. It is used always, but in a single-thread environment it won't change anything.

There is a new option to `Grocer.pusher` for `:pool_size` (defaults to 5). This option is not passed along to `PushConnection`, but the remaining options are.

``` ruby
pusher = Grocer.pusher(certificate: my_cert, pool_size: 8)
pusher.push(notification)
```

Internally `.pusher` just creates a `PushConnectionPool` instead of a `PushConnection`. The connection pool has an `#acquire` method that accepts a block and consumes an open connection until the block returns. The pool fills lazily, until it reaches it's maximum size (i.e. 5 simultaneous threads sending a push notification at once), at which point other requests to write to the pool must wait in a queue.

The connection pool has a `#write` method to hide the fact it needs to acquire and release connections internally.