Skip to content

Commit

Permalink
Ensure goroutine has started before sending data
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Nov 12, 2023
1 parent e195c31 commit d522431
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/cmd/benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ func benchmark_data(data string, opts benchmark_options) (duration time.Duration
defer func() { _, _ = term.WriteString(state.ResetStateEscapeCodes() + reset) }()
lock := sync.Mutex{}
const count = 3
goroutine_started := make(chan byte)

go func() {
lock.Lock()
defer lock.Unlock()
buf := make([]byte, 8192)
var data []byte
q := []byte(strings.Repeat("\x1b[0n", count))
goroutine_started <- 'y'
for !bytes.Contains(data, q) {
n, err := term.Read(buf)
if err != nil {
Expand All @@ -75,6 +77,7 @@ func benchmark_data(data string, opts benchmark_options) (duration time.Duration
data = append(data, buf[:n]...)
}
}()
<-goroutine_started

start := time.Now()
repeat_count := opts.repeat_count
Expand Down

0 comments on commit d522431

Please sign in to comment.