Skip to content

Commit ae4fd13

Browse files
author
heraclmene
committed
Ensure goroutine is always closed when a response is returned.
1 parent 591f634 commit ae4fd13

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

remote_driver_helpers.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ func UntilElementPresent(by By, sleep time.Duration) Until {
2424

2525
func (s *seleniumWebDriver) Wait(u Until, timeout time.Duration) (bool, error) {
2626
response := make(chan *waitResponse, 1)
27+
quit := make(chan bool, 1)
2728

2829
go func() {
2930
for {
30-
s, e := u(s)
31-
if e == nil && s {
32-
response <- &waitResponse{s: s, e: e}
31+
select {
32+
case <-quit:
3333
break
34+
default:
35+
s, e := u(s)
36+
if e == nil && s {
37+
response <- &waitResponse{s: s, e: e}
38+
break
39+
}
3440
}
3541
}
3642
}()
@@ -39,6 +45,7 @@ func (s *seleniumWebDriver) Wait(u Until, timeout time.Duration) (bool, error) {
3945
case r := <-response:
4046
return r.s, r.e
4147
case <-time.After(timeout):
48+
close(quit)
4249
return false, WaitTimeoutError
4350
}
4451
}

0 commit comments

Comments
 (0)