Skip to content

Commit

Permalink
fix(main): fix closing of results channel
Browse files Browse the repository at this point in the history
The `results` channel is now closed in the `defer` statement instead of after an error occurred. This ensures that the channel is always closed properly.
  • Loading branch information
NOBLES5E committed Aug 4, 2023
1 parent 2442503 commit 38a3a3a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions main.go
Expand Up @@ -104,6 +104,7 @@ func readRecordFile(url string, recordDirPath string) (*FeedProgress, error) {
}

func fetchFeed(url string, results chan *gofeed.Item, recordDirPath string, continueFetch bool, timeoutSeconds int) {
defer close(results)
fp := gofeed.NewParser()
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutSeconds)*time.Second)
defer cancel()
Expand Down Expand Up @@ -170,6 +171,4 @@ func fetchFeed(url string, results chan *gofeed.Item, recordDirPath string, cont
log.Fatal(err)
}
}

close(results)
}

0 comments on commit 38a3a3a

Please sign in to comment.