Sha256: aec229ff5f6677ba7bb6580d55b9c8e1e776181980775ac7849f64b9090b9382
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
require "spec/helper/all" require "em-synchrony/fiber_iterator" describe EventMachine::Synchrony::FiberIterator do it "should wait until the iterator is done and wrap internal block within a fiber" do EM.synchrony do results = [] i = EM::Synchrony::FiberIterator.new(1..5, 2).each do |num| EM::Synchrony.sleep(0.1) results.push num end results.should == (1..5).to_a results.size.should == 5 EventMachine.stop 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 # data = (1..5).to_a # res = EM::Synchrony::FiberIterator.new(data, 2).inject(0) do |total, num, iter| # EM::Synchrony.sleep(0.1) # # p [:sync, total, num] # iter.return(total += num) # end # # res.should == data.inject(:+) # EventMachine.stop # end # end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
em-synchrony-1.0.6 | spec/fiber_iterator_spec.rb |
em-synchrony-1.0.5 | spec/fiber_iterator_spec.rb |