I think you're reusing your *Operation
which is causing issues. For example:
http://play.golang.org/p/_MeSBLWPwN
c := make(chan *int, 1)
go func() {
val := new(int)
for i :=0; i<10; i++ {
*val = i
c <- val
}
close(c)
}()
for val := range c {
time.Sleep(time.Millisecond * 1)
fmt.Println(*val)
}
This code results in:
2
3
4
5
6
7
8
9
9
9
And more importantly it's not thread safe. Try doing this maybe:
for {
for {
var oper *Operation
if !iter.Next(&oper) {
break
}
fmt.Println("\n<<", oper.Id)
Out <- oper
}
...
}
Or use a plain Operation
instead of a *Operation
. (Because without the pointer the value is copied)