Files
obitools4/pkg/obiformats/dispatcher.go

49 lines
957 B
Go
Raw Normal View History

package obiformats
import (
"fmt"
"log"
"sync"
2022-02-14 09:12:57 +01:00
"sync/atomic"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
)
type SequenceBatchWriterToFile func(iterator obiseq.IBioSequenceBatch,
filename string,
options ...WithOption) (obiseq.IBioSequenceBatch, error)
func WriterDispatcher(prototypename string,
dispatcher obiseq.IDistribute,
formater SequenceBatchWriterToFile,
options ...WithOption) {
jobDone := sync.WaitGroup{}
jobDone.Add(1)
go func() {
2022-02-14 09:12:57 +01:00
n := int32(0)
for newflux := range dispatcher.News() {
2022-02-14 09:12:57 +01:00
go func(newflux string) {
data, _ := dispatcher.Outputs(newflux)
out, err := formater(data,
fmt.Sprintf(prototypename, newflux),
options...)
if err != nil {
log.Fatalf("cannot open the output file for key %s", newflux)
}
atomic.AddInt32(&n, 1)
if atomic.LoadInt32(&n) > 1 {
jobDone.Add(1)
}
out.Recycle()
jobDone.Done()
2022-02-14 09:12:57 +01:00
}(newflux)
}
}()
jobDone.Wait()
}