Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Speed up event processing #8

Merged
merged 12 commits into from
Apr 24, 2020
Prev Previous commit
Next Next commit
Add semaphore to pushing
Can't have too many rsyncs flying around.
  • Loading branch information
ammario committed Apr 24, 2020
commit 65be003dafbcd3f06f7a11050e287ecdd7929976
5 changes: 5 additions & 0 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/gorilla/websocket"
"github.com/rjeczalik/notify"
"go.coder.com/flog"
"golang.org/x/sync/semaphore"
"golang.org/x/xerrors"

"cdr.dev/coder-cli/internal/entclient"
Expand Down Expand Up @@ -192,13 +193,17 @@ func (s Sync) workEventGroup(evs []timedEvent) {
s.work(ev)
}

sem := semaphore.NewWeighted(8)

var wg sync.WaitGroup
for _, ev := range cache.ConcurrentEvents() {
setConsoleTitle(fmtUpdateTitle(ev.Path()))

wg.Add(1)
sem.Acquire(context.Background(), 1)
ev := ev
go func() {
defer sem.Release(1)
defer wg.Done()
s.work(ev)
}()
Expand Down