Skip to content

Commit 0475661

Browse files
authored
Merge pull request #127 from gofiber/codex/2025-07-09-13-01-54
2 parents f345bf8 + c038a71 commit 0475661

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

cmd/dev.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"runtime"
1515
"strconv"
1616
"strings"
17+
"sync"
1718
"sync/atomic"
1819
"syscall"
1920
"time"
@@ -77,6 +78,8 @@ type escort struct {
7778
watcherErrors chan error
7879
sig chan os.Signal
7980

81+
wg sync.WaitGroup
82+
8083
binPath string
8184
bin *exec.Cmd
8285
stdoutPipe io.ReadCloser
@@ -108,14 +111,17 @@ func (e *escort) run() (err error) {
108111
_ = os.Remove(e.binPath)
109112
}()
110113

111-
go e.runBin()
112-
go e.watchingBin()
113-
go e.watchingFiles()
114+
e.wg.Add(3)
115+
go func() { defer e.wg.Done(); e.runBin() }()
116+
go func() { defer e.wg.Done(); e.watchingBin() }()
117+
go func() { defer e.wg.Done(); e.watchingFiles() }()
114118

115119
signal.Notify(e.sig, syscall.SIGTERM, syscall.SIGINT, os.Interrupt)
116120
<-e.sig
117121

118122
e.terminate()
123+
close(e.hitCh)
124+
e.wg.Wait()
119125

120126
log.Println("See you next time 👋")
121127

@@ -153,7 +159,11 @@ func (e *escort) init() (err error) {
153159
e.binPath += ".exe"
154160
}
155161

156-
e.hitFunc = e.runBin
162+
e.hitFunc = func() {
163+
e.wg.Add(1)
164+
e.runBin()
165+
e.wg.Done()
166+
}
157167

158168
e.preRunCommands = parsePreRunCommands(c.preRun)
159169

@@ -214,15 +224,22 @@ func (e *escort) watchingFiles() {
214224

215225
func (e *escort) watchingBin() {
216226
var timer *time.Timer
217-
for range e.hitCh {
218-
// reset timer
219-
if timer != nil && !timer.Stop() {
220-
select {
221-
case <-timer.C:
222-
default:
227+
for {
228+
select {
229+
case <-e.ctx.Done():
230+
if timer != nil {
231+
timer.Stop()
232+
}
233+
return
234+
case <-e.hitCh:
235+
if timer != nil && !timer.Stop() {
236+
select {
237+
case <-timer.C:
238+
default:
239+
}
223240
}
241+
timer = time.AfterFunc(e.delay, e.hitFunc)
224242
}
225-
timer = time.AfterFunc(e.delay, e.hitFunc)
226243
}
227244
}
228245

cmd/dev_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,5 +312,7 @@ func getEscort() *escort {
312312
},
313313
ctx: c,
314314
terminate: t,
315+
hitCh: make(chan struct{}, 1),
316+
sig: make(chan os.Signal, 1),
315317
}
316318
}

cmd/internal/prompt.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package internal
22

33
import (
44
"fmt"
5+
"os"
56

67
input "github.com/charmbracelet/bubbles/textinput"
78
tea "github.com/charmbracelet/bubbletea"
9+
"github.com/muesli/termenv"
810
)
911

1012
type errMsg error
@@ -27,7 +29,7 @@ func NewPrompt(title string, placeholder ...string) *Prompt {
2729
p.textInput.Placeholder = placeholder[0]
2830
}
2931

30-
p.p = tea.NewProgram(p)
32+
p.p = tea.NewProgram(p, tea.WithOutput(termenv.NewOutput(os.Stdout)))
3133

3234
return p
3335
}

0 commit comments

Comments
 (0)