Files
obitools4/pkg/obiformats/dispatcher.go

52 lines
1.0 KiB
Go
Raw Normal View History

package obiformats
import (
"fmt"
"sync"
2023-01-22 22:04:17 +01:00
log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
)
2023-01-22 22:04:17 +01:00
type SequenceBatchWriterToFile func(iterator obiiter.IBioSequence,
filename string,
2023-01-22 22:04:17 +01:00
options ...WithOption) (obiiter.IBioSequence, error)
func WriterDispatcher(prototypename string,
dispatcher obiiter.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()
}