From 08fafa7282ac9cff372718d11ca53dd2764219fb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 15 Aug 2024 04:00:44 +0900 Subject: refactor: simplify cancel --- main.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index d9bedb4..288e295 100644 --- a/main.go +++ b/main.go @@ -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 } -- cgit v1.2.3-70-g09d2