Skip to content

Commit

Permalink
Merge pull request igrigorik#202 from exAspArk/fiber_iterator
Browse files Browse the repository at this point in the history
Fix passing nested arrays to FIberIterator with iter
  • Loading branch information
igrigorik committed Mar 4, 2016
2 parents 7bd47d5 + a11689a commit cf1a6ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/em-synchrony/fiber_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class FiberIterator < EM::Synchrony::Iterator
# and auto-advance the iterator after each call
def each(foreach=nil, after=nil, &blk)
fe = Proc.new do |obj, iter|
Fiber.new { (foreach || blk).call(obj); iter.next }.resume
Fiber.new { (foreach || blk).call(obj, iter); iter.next }.resume
end

super(fe, after)
Expand Down
13 changes: 13 additions & 0 deletions spec/fiber_iterator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
end
end

it "works even with nested arrays and iterator" do
EM.synchrony do
results = []
list = [[1, 2], [3, 4]]

EM::Synchrony::FiberIterator.new(list, 2).each { |sublist, iter| results.push(sublist) }

expect(results).to eq(list)

EM.stop
end
end

#
# it "should sum values within the iterator" do
# EM.synchrony do
Expand Down

0 comments on commit cf1a6ee

Please sign in to comment.