mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 17:20:18 +01:00
interleaver: Run producer and consumer in separate go routines.
This commit is contained in:
parent
82be84d449
commit
fc50897d2d
@ -49,17 +49,32 @@ func selectKeyEncoder(interleaved bool) common.KeyEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func copyProducerToConsumer(producer BlockProducer, consumer BlockConsumer) (err error) {
|
func copyProducerToConsumer(producer BlockProducer, consumer BlockConsumer) (err error) {
|
||||||
var block Block
|
|
||||||
i := 0
|
blocks := make(chan *Block)
|
||||||
|
done := make(chan struct{})
|
||||||
|
defer close(done)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer close(blocks)
|
||||||
for {
|
for {
|
||||||
if err = producer.Next(&block); err != nil {
|
block := new(Block)
|
||||||
if err == ErrNoMoreBlocks {
|
if err = producer.Next(block); err != nil {
|
||||||
err = nil
|
if err != ErrNoMoreBlocks {
|
||||||
break
|
log.Printf("Reading failed: %s\n", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = consumer.Consume(&block); err != nil {
|
select {
|
||||||
|
case blocks <- block:
|
||||||
|
case <-done:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for block := range blocks {
|
||||||
|
if err = consumer.Consume(block); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
|
Loading…
Reference in New Issue
Block a user