parallelize fetching feeds

This commit is contained in:
filifa 2024-06-18 18:35:16 -05:00
parent 1b248ddbbb
commit aa5b4923a3
1 changed files with 13 additions and 4 deletions

View File

@ -44,12 +44,21 @@ func rssfetch(cmd *cobra.Command, urls []string) {
} }
fp := gofeed.NewParser() fp := gofeed.NewParser()
var feedChs []chan *gofeed.Feed
for _, url := range urls { for _, url := range urls {
feed, err := fp.ParseURL(url) ch := make(chan *gofeed.Feed)
if err != nil { go func(url string) {
log.Fatal(err) feed, err := fp.ParseURL(url)
} if err != nil {
log.Fatal(err)
}
ch <- feed
}(url)
feedChs = append(feedChs, ch)
}
for _, feedCh := range feedChs {
feed := <-feedCh
for _, item := range feed.Items { for _, item := range feed.Items {
out, err := formatItem(item, tmpl) out, err := formatItem(item, tmpl)
if err != nil { if err != nil {