Channel übergabe mit einem Buffer von 10 Plätzen für Länderdatensätze

This commit is contained in:
Marco Kittel 2025-06-29 08:20:36 +02:00
parent c3826f7f92
commit dd6cb28e9a
1 changed files with 13 additions and 2 deletions

View File

@ -16,7 +16,14 @@ type filedata struct {
filename string
dt time.Time
}
type ElioHandleFunc func(filename string) bool
// Daten über Channel aus der Goroutine ausführen. CounterID stellt sicher, dass das Herkunftsland der Daten bekannt ist.
type CountryCsvData struct {
CountryID string
Data []string
}
type ElioHandleFunc func(filename string, data chan<- CountryCsvData) bool
type ElioDateiFoo struct {
process ElioHandleFunc
@ -68,6 +75,9 @@ func (f *ElioDateiFoo) ScanCsv() {
}
}
}
//BufferedChannel mit Platz für 10 Datensätzen
dataChannel := make(chan CountryCsvData, 10)
for _, v := range filemap {
f.mu.RLock()
_, ok := f.haveDone[v.filename]
@ -75,9 +85,10 @@ func (f *ElioDateiFoo) ScanCsv() {
if ok {
break
}
//Todo: Goroutine Einbauen, die alte Datensätze aus der Map entfernt
f.mu.Lock()
f.haveDone[v.filename] = time.Now()
f.mu.Unlock()
go f.process(v.filename)
go f.process(v.filename, dataChannel)
}
}