From: Charles Oliver Nutter Date: 2007-11-29T00:41:15+09:00 Subject: Re: Ruby needs continuations... MonkeeSage wrote: > You actually need a generator, which can be implemented with > continuations, but doesn't have to be (in 1.9 the generators are > implemented with threads -- have a look at generator.rb in 1.8 and 1.9 > to see the differences). Using generators, you can implement izip (and > all of itertools if you'd like, though most of it already has > equivalent ruby solutions). Here is a pretty close translation of the > python given in the itertools docs: Ruby 1.9 also moves continuations out of core, but provides a form of bounded continuations (coroutines) that's possible to implement in JRuby: require 'fiber' f = Fiber.new { a = 1; while true; Fiber.yield a; a += 1; end } 5.times { puts f.resume } $ jruby -J-Djruby.compat.version=ruby1_9 fiber_example.rb 1 2 3 4 5 Under JRuby, it's using a native thread per live Fiber, so it's heavier than in Ruby 1.9 which uses green threads. However they'll actually run in parallel on JRuby, so that's a benefit. JRuby also supports a thread pool in 1.1 that helps blunt the cost of spinning up native threads. - Charlie