fixes race condition when EventLoad listener isn't removed prior to the next page loading (#281)

This commit is contained in:
Adam Argo
2019-05-10 13:14:38 -04:00
committed by Tim Voronov
parent 101da6323a
commit 65b6981a8e
+4 -1
View File
@@ -704,8 +704,11 @@ func (doc *HTMLDocument) WaitForClassBySelectorAll(ctx context.Context, selector
func (doc *HTMLDocument) WaitForNavigation(ctx context.Context) error {
onEvent := make(chan struct{})
var once sync.Once
listener := func(_ context.Context, _ interface{}) {
close(onEvent)
once.Do(func() {
close(onEvent)
})
}
defer doc.events.RemoveEventListener(events.EventLoad, listener)