From eab418afc7c78f8df2cb8e713e7e2e89a8fd4135 Mon Sep 17 00:00:00 2001 From: Jesse Wolgamott Date: Thu, 19 Feb 2015 13:14:59 -0600 Subject: [PATCH] Instructions for ActiveRecord Usage. Closes #2 --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 944f4fc..5327922 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,19 @@ The pmap will return an array of values when all of the Futures have completed a The pool can help to make sure you don't exceed your connection resources. A common use case for this is in Rails, you can easily exceed the default ActiveRecord connection size. +### Use with ActiveRecord + +Some users have reported connection leaking with using ActiveRecord objects in a +pmap. You can reuse a connection with this code below. You can read the backstory +on the [decision to not include an AR dependency](https://github.com/jwo/celluloid-pmap/pull/2). + +```ruby +users.pmap(4) do |user| + ActiveRecord::Base.connection_pool.with_connection { user.do_hefty_stuff! } +end +``` + + ### Inspiration for this code Tony Arcieri created [celluloid](http://celluloid.io/), and the [simple_pmap example](https://github.com/celluloid/celluloid/blob/master/examples/simple_pmap.rb) from which this codebase started