mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
chore: use sync.WaitGroup.Go when possible (#1996)
* chore: use sync.WaitGroup.Go when possible * Update internal/watcher/watcher.go Co-authored-by: Alexandre Daubois <2144837+alexandre-daubois@users.noreply.github.com> --------- Co-authored-by: Alexandre Daubois <2144837+alexandre-daubois@users.noreply.github.com>
This commit is contained in:
@@ -53,18 +53,19 @@ func InitWatcher(ct context.Context, filePatterns []string, callback func(), slo
|
||||
if len(filePatterns) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if watcherIsActive.Load() {
|
||||
return ErrAlreadyStarted
|
||||
}
|
||||
|
||||
watcherIsActive.Store(true)
|
||||
ctx = ct
|
||||
logger = slogger
|
||||
activeWatcher = &watcher{callback: callback}
|
||||
err := activeWatcher.startWatching(ctx, filePatterns)
|
||||
if err != nil {
|
||||
|
||||
if err := activeWatcher.startWatching(ctx, filePatterns); err != nil {
|
||||
return err
|
||||
}
|
||||
reloadWaitGroup = sync.WaitGroup{}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -73,6 +74,7 @@ func DrainWatcher() {
|
||||
if !watcherIsActive.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
watcherIsActive.Store(false)
|
||||
|
||||
if logger.Enabled(ctx, slog.LevelDebug) {
|
||||
|
||||
@@ -66,15 +66,12 @@ func initPHPThreads(numThreads int, numMaxThreads int, phpIni map[string]string)
|
||||
}
|
||||
|
||||
// start the underlying C threads
|
||||
ready := sync.WaitGroup{}
|
||||
ready.Add(numThreads)
|
||||
var ready sync.WaitGroup
|
||||
|
||||
for i := 0; i < numThreads; i++ {
|
||||
thread := phpThreads[i]
|
||||
go func() {
|
||||
thread.boot()
|
||||
ready.Done()
|
||||
}()
|
||||
ready.Go(phpThreads[i].boot)
|
||||
}
|
||||
|
||||
ready.Wait()
|
||||
|
||||
return mainThread, nil
|
||||
|
||||
10
worker.go
10
worker.go
@@ -36,7 +36,6 @@ var (
|
||||
|
||||
func initWorkers(opt []workerOpt) error {
|
||||
workers = make([]*worker, 0, len(opt))
|
||||
workersReady := sync.WaitGroup{}
|
||||
directoriesToWatch := getDirectoriesToWatch(opt)
|
||||
watcherIsEnabled = len(directoriesToWatch) > 0
|
||||
|
||||
@@ -48,15 +47,16 @@ func initWorkers(opt []workerOpt) error {
|
||||
workers = append(workers, w)
|
||||
}
|
||||
|
||||
var workersReady sync.WaitGroup
|
||||
|
||||
for _, w := range workers {
|
||||
workersReady.Add(w.num)
|
||||
for i := 0; i < w.num; i++ {
|
||||
thread := getInactivePHPThread()
|
||||
convertToWorkerThread(thread, w)
|
||||
go func() {
|
||||
|
||||
workersReady.Go(func() {
|
||||
thread.state.waitFor(stateReady)
|
||||
workersReady.Done()
|
||||
}()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user