diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-15 04:00:44 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-15 04:00:44 +0900 |
| commit | 08fafa7282ac9cff372718d11ca53dd2764219fb (patch) | |
| tree | 496aaee704f212d25c35057cf14800d7456f04b5 | |
| parent | 14efa09532599b9a8af7aac8819be148da488aaa (diff) | |
| download | feedaka-08fafa7282ac9cff372718d11ca53dd2764219fb.tar.gz feedaka-08fafa7282ac9cff372718d11ca53dd2764219fb.tar.zst feedaka-08fafa7282ac9cff372718d11ca53dd2764219fb.zip | |
refactor: simplify cancel
| -rw-r--r-- | main.go | 9 |
1 files changed, 3 insertions, 6 deletions
@@ -441,8 +441,7 @@ func apiPutArticle(c echo.Context, op string) error { return c.NoContent(http.StatusOK) } -func scheduled(d time.Duration, fn func(), doneC chan struct{}, ctx context.Context) { - defer close(doneC) +func scheduled(ctx context.Context, d time.Duration, fn func()) { ticker := time.NewTicker(d) go func() { for { @@ -498,15 +497,13 @@ func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - doneC := make(chan struct{}) - scheduled(1*time.Hour, func() { + scheduled(ctx, 1*time.Hour, func() { err := fetchAllFeeds(ctx) if err != nil { log.Printf("Failed to fetch feeds: %v\n", err) } - }, doneC, ctx) + }) err = http.ListenAndServe(":"+port, http.StripPrefix(basePath, e)) log.Println(err) - <-doneC } |
