------ art_2399_833396.1140021947431 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 2/14/06, Ross Bamford <rossrt / roscopeco.co.uk> wrote: > It seems to be jumping early out of the endless test judging by the > number of missing assertions. It only happens sometimes (1561 is a full > pass) and it does happen with the old version too (only just noticed > it). I hope I've fixed the thread bugs I had. At least, I can no longer duplicate this problem. In the tests file you sent me, I made the following change: - c = 0 - until t.stop? - if c >= 30 - t.kill - fail "Endless iterators unsupported" - end - - c += 1 - sleep(1) - end + fail "Endless iterators unsupported" unless t.join(30) Dave ------ art_2399_833396.1140021947431 Content-Type: application/octet-stream; name=my_generator.rb Content-Transfer-Encoding: 7bit X-Attachment-Id: f_ejpvlltr Content-Disposition: attachment; filename="my_generator.rb" class MyGenerator def self.stateless(enum il, &block) g ew(enum, &block) g.instance_variable_set(:@stateless, true) g end def initialize(enum il, &block) @index @stateless alse if enum if enum.respond_to? :to_ary @array num.to_ary else block roc { |g| enum.each { |x| g.yield x } } end end if block @array rray.new @block lock [ :current, :end?, :next?, :next ].each do |symbol| method ethod(symbol) metaclass.define_method(symbol) { |*args| fill_from_block; method.call(*args) } end end raise ArgumentError, 'Generate nothing?' unless @array end def current @array.fetch(@index) rescue raise EOFError end def each(&each_block) if @array @array.each(&each_block) else x bject.new def x.yield(value); each_block.call(value); end @block.call(x) end self end def end? @index > array.size end attr_reader :index alias_method :pos, :index def next begin result array.fetch(@index) rescue Exception e puts e if @index ! raise EOFError end @index + result end def next? @index < @array.size end def rewind @index if @block @array rray.new if @block @thread ew_fill_thread end self end def yield(value) @array << value Thread.stop if not @stateless self end private def spent? @index > array.size end def metaclass class << self public_class_method :define_method self end end def new_fill_thread Thread.new { @block.call(self) } end def fill_from_block return if not spent? or @block_exhausted @thread || ew_fill_thread return unless @thread.alive? if @stateless @block_exhausted thread.join(1) else while spent? and @thread.alive? @thread.wakeup Thread.pass end end end end ------ art_2399_833396.1140021947431--