1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-11-06 08:39:09 +02:00

change WaitForNavigation to avoid race condition/panic sending on closed channel (#84)

This commit is contained in:
Adam Argo
2018-10-09 06:19:58 -07:00
committed by Tim Voronov
parent 65a7f2a2df
commit c498da4a21

View File

@@ -557,26 +557,20 @@ func (doc *HTMLDocument) WaitForClassAll(selector, class values.String, timeout
}
func (doc *HTMLDocument) WaitForNavigation(timeout values.Int) error {
timer := time.NewTimer(time.Millisecond * time.Duration(timeout))
onEvent := make(chan bool)
onEvent := make(chan struct{})
listener := func(_ interface{}) {
onEvent <- true
close(onEvent)
}
defer doc.events.RemoveEventListener("load", listener)
defer close(onEvent)
doc.events.AddEventListener("load", listener)
for {
select {
case <-onEvent:
timer.Stop()
return nil
case <-timer.C:
return core.ErrTimeout
}
select {
case <-onEvent:
return nil
case <-time.After(time.Millisecond * time.Duration(timeout)):
return core.ErrTimeout
}
}