Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow batches without initial enumerable

  • Loading branch information...
commit dbd3c7f9cadee2b2d679072d116a6c0d2f7cb15c 1 parent faa90fe
@mperham authored
Showing with 14 additions and 5 deletions.
  1. +3 −4 lib/girl_friday/batch.rb
  2. +11 −1 test/test_batch.rb
View
7 lib/girl_friday/batch.rb
@@ -12,15 +12,14 @@ module GirlFriday
#
# TODO Errors are not handled well at all.
class Batch
- def initialize(enumerable, options, &block)
+ def initialize(enumerable=nil, options, &block)
@queue = GirlFriday::Queue.new(:batch, options, &block)
@complete = 0
+ @size = 0
+ @results = []
if enumerable
@size = enumerable.count
@results = Array.new(@size)
- else
- @size = 0
- @results = []
end
@lock = Mutex.new
@condition = ConditionVariable.new
View
12 test/test_batch.rb
@@ -40,6 +40,16 @@ def test_batch_timeout
sleep 0.1
end
+ def test_empty_batch
+ batch = GirlFriday::Batch.new(:size => 4) do |msg|
+ sleep msg
+ 'x'
+ end
+ values = batch.results
+ values.must_be_kind_of Array
+ values.must_equal []
+ end
+
def test_streaming_batch_api
batch = GirlFriday::Batch.new(nil, :size => 4) do |msg|
sleep msg
@@ -54,7 +64,7 @@ def test_streaming_batch_api
b = Time.now
values.must_be_kind_of Array
values.must_equal %w(x x x x)
- assert_in_delta 0.1, (b - a), 0.1
+ assert_in_delta 0.2, (b - a), 0.1
assert_raises ArgumentError do
batch << 0.1
Please sign in to comment.
Something went wrong with that request. Please try again.