I am trying to use
IterTools with several channel iterators. A simple example:
using IterTools mkfunc(lst) = function(c) for elem in lst println("producing val $elem") put!(c, elem) println("returned from put for $elem") end end channel1 = Channel(mkfunc([1, 2])) channel2 = Channel(mkfunc([3, 4])) for (v1, v2) in product(channel1, channel2) println("$v1, $v2") end
This code fails with
ERROR: LoadError: UndefRefError: access to undefined reference
in the middle of the iteration.
The reason, as far as I understand it, is that the
next() relies on
done() (and, consequently,
take!()) being called before it to populate the state’s
val field. Which is what, say,
for cycle normally does. But
next() right away after
start(), which leads to the state’s value being undefined.
If my reasoning is correct, who is at fault here?
next()implementation relying on the
product()implementation not calling
- The iteration protocol documentation not specifying that
done()should be called before