Ensure goroutine has started before sending data

This commit is contained in:
Kovid Goyal
2023-11-12 16:58:37 +05:30
parent 0f6e5fe57e
commit 24232ba277

View File

@@ -60,6 +60,7 @@ 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()
@@ -67,6 +68,7 @@ func benchmark_data(data string, opts benchmark_options) (duration time.Duration
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 {
@@ -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