Fix: expect: When monitoring words were output in succession, the latter was sometimes overlooked

This commit is contained in:
HAYAMA_Kaoru
2024-12-05 13:55:33 +09:00
parent c3e82c5bd9
commit 41dc2eb1fd
+7
View File
@@ -77,6 +77,9 @@ func (W *Watcher) checkWords(token string, words []string) int {
}
func (W *Watcher) Expect(words ...string) int {
if found := W.checkWords("", words); found >= 0 {
return found
}
for {
select {
case token := <-W.ch:
@@ -90,6 +93,10 @@ func (W *Watcher) Expect(words ...string) int {
}
func (W *Watcher) ExpectWithTimeout(d time.Duration, words ...string) int {
if found := W.checkWords("", words); found >= 0 {
return found
}
timer := time.NewTimer(d)
defer timer.Stop()