g forever wrote:
>Parallel iterators and streams without threads - Call to experts

That's not me, but I'll speak up anyway.

>After trial and error I found a way to iterate over two streams in parallel.
>Being new to Ruby it was an useful exercise in forcing me to look intensely
>at a lot of features. The solution below works, but I have three isuues.
>
>(foo,bar) do |i,j|
>     #process i and j as needed
>     yield i,j   # to achieve closure
>end

I assume the actual target situation is much more 
complex than the simple example (they usually 
are). However, being my 'simple' self, I would 
look for a way to work with the language instead 
of against it. In this case, I would hope to get 
away with something simple like:

def test
  first = []
  foo { |i| first << i}
  bar do
    |j|
    i = first.shift
    print "#{i},#{j}\n"
    #process i and j as needed
    #yield i,j   # to achieve closure
  end
end

The only drawbacks I can see are: 1) It iterates 
through one stream entirely before the other. As 
long as the two streams are unrelated, that 
shouldn't be a problem. 2) It only loops for the 
length of the second stream, so extra items in 
the first stream would be ignored. (But your 
approach didn't seem to handle this situation 
either). 3) It stores the entire foo result set 
in memory. If that's really a problem you could 
probably write a little cache loop that grabbed 
10 at a time from foo and bar, processed those, 
then went back for more.

I'm probably oversimplifying your real-world 
needs. But I just wanted to point out the brute-
force solution, because many times it's all that 
is really needed. And it sure is easier to write, 
maintain, understand, etc.

Kevin