From 41dc2eb1fdbd1b557e45eaa7fa5837a796056c23 Mon Sep 17 00:00:00 2001 From: HAYAMA_Kaoru Date: Thu, 5 Dec 2024 12:52:14 +0900 Subject: [PATCH] Fix: expect: When monitoring words were output in succession, the latter was sometimes overlooked --- watcher.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/watcher.go b/watcher.go index 60de37a..5027a46 100644 --- a/watcher.go +++ b/watcher.go @@ -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()