massively simplify

This commit is contained in:
filifa 2024-06-18 19:49:31 -05:00
parent 34abeeb37b
commit bd28927a4e
1 changed files with 13 additions and 18 deletions

View File

@ -41,26 +41,21 @@ func formatItem(item *gofeed.Item, tmpl *template.Template) (string, error) {
// along with any parsing errors.
func parseFeeds(urls []string) ([]*gofeed.Feed, []error) {
fp := gofeed.NewParser()
feedChs := make([]chan *gofeed.Feed, len(urls))
errChs := make([]chan error, len(urls))
for i, url := range urls {
feedCh := make(chan *gofeed.Feed)
errCh := make(chan error)
go func(url string) {
feed, err := fp.ParseURL(url)
feedCh <- feed
errCh <- err
}(url)
feedChs[i] = feedCh
errChs[i] = errCh
}
feeds := make([]*gofeed.Feed, len(urls))
errs := make([]error, len(urls))
for i := range feedChs {
feeds[i] = <-feedChs[i]
errs[i] = <-errChs[i]
done := make(chan int)
for i, url := range urls {
go func(i int, url string) {
feed, err := fp.ParseURL(url)
feeds[i] = feed
errs[i] = err
done <- i
}(i, url)
}
for i := 0; i < len(urls); i++ {
<-done
}
return feeds, errs