Files
obitools4/pkg/obiformats/dispatcher.go

51 lines
1.0 KiB
Go
Raw Normal View History

package obiformats
import (
"fmt"
"log"
"sync"
"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() {
for newflux := range dispatcher.News() {
jobDone.Add(1)
2022-02-18 22:53:09 +01:00
go func(newflux int) {
data, err := dispatcher.Outputs(newflux)
if err != nil {
log.Fatalf("Cannot retreive the new chanel : %v", err)
}
2022-02-14 09:12:57 +01:00
out, err := formater(data,
fmt.Sprintf(prototypename, dispatcher.Classifier().Value(newflux)),
2022-02-14 09:12:57 +01:00
options...)
2022-02-14 09:12:57 +01:00
if err != nil {
log.Fatalf("cannot open the output file for key %s",
dispatcher.Classifier().Value(newflux))
2022-02-14 09:12:57 +01:00
}
out.Recycle()
jobDone.Done()
2022-02-14 09:12:57 +01:00
}(newflux)
}
jobDone.Done()
}()
jobDone.Wait()
}