small pixel drawing of a pufferfish vore

awful worker pool implementation
Jes Olson j3s@c3f.net
Wed, 14 Jun 2023 22:06:57 -0500
commit

0bc6feae60ba63f362e9cbfacff8981e10f582de

parent

de0eecf513a85149b2167a81ac0e41822be11b4f

1 files changed, 10 insertions(+), 5 deletions(-)

jump to
M reaper/reaper.goreaper/reaper.go

@@ -1,9 +1,9 @@

package reaper import ( + "fmt" "log" "sort" - "sync" "time" "git.j3s.sh/vore/rss"

@@ -59,17 +59,22 @@ // UpdateAll fetches every feed & attempts updating them

// asynchronously, then prints the duration of the sync func (r *Reaper) refreshAllFeeds() { start := time.Now() - var wg sync.WaitGroup + semaphore := make(chan struct{}, 20) + for i := range r.feeds { if r.feeds[i].Stale() { - wg.Add(1) + semaphore <- struct{}{} + fmt.Println(r.feeds[i].UpdateURL) + go func(f *rss.Feed) { - defer wg.Done() + // ensure we always free the channel + defer func() { + <-semaphore + }() r.refreshFeed(f) }(r.feeds[i]) } } - wg.Wait() log.Printf("reaper: refresh complete in %s\n", time.Since(start)) }